Skip to content

feat: convert DatabaseType from enum to string-based struct#304

Merged
datlechin merged 2 commits intomainfrom
feat/open-database-type-struct
Mar 13, 2026
Merged

feat: convert DatabaseType from enum to string-based struct#304
datlechin merged 2 commits intomainfrom
feat/open-database-type-struct

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

  • Converts DatabaseType from a closed 11-case enum to a Hashable/Codable/Sendable string-based struct, enabling future plugins to register new database types without modifying the app
  • Replaces all switch-based computed properties with static dictionary/set lookups that return sensible defaults for unknown types
  • Adds allKnownTypes array (with allCases compatibility shim), init?(validating:) failable initializer, and availableDatabaseTypes on PluginManager

Changes

Core conversion (DatabaseConnection.swift):

  • struct DatabaseType with let rawValue: String, static constants for all 11 built-in types
  • Explicit Codable (bare string encoding), Hashable, Sendable conformance
  • All computed properties (pluginTypeId, iconName, defaultPort, requiresAuthentication, supportsForeignKeys, supportsSchemaEditing, isDownloadablePlugin) use dictionary/set lookups with defaults for unknown types

Switch statements (~15 files):

  • Converted all switch on DatabaseType to if/else chains or dictionary lookups with default: fallbacks

Call site updates (3 files):

  • ConnectionFormView: allCasesallKnownTypes
  • DeeplinkHandler: DatabaseType(rawValue:)DatabaseType(validating:) + allKnownTypes
  • ConnectionStorage: removed ?? .mysql fallback (init is now non-failable)

Infrastructure:

  • PluginManager.availableDatabaseTypes computed property (ready for Phase 4.2)
  • Theme.defaultDatabaseColor for unknown type fallback

Tests (3 files):

  • Updated existing tests for struct API
  • Added 7 new tests: struct equality, unknown type round-trip, validating init, Codable round-trip (known + unknown), Hashable set membership

Test plan

  • Build succeeds (xcodebuild build)
  • All DatabaseType tests pass (DatabaseTypeTests, DatabaseTypeMSSQLTests, DatabaseTypeRedisTests)
  • No DatabaseType.allCases references remain in app code
  • No CaseIterable conformance on DatabaseType
  • Manual: open app, create connections of different types, verify icons/ports/colors display correctly

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 13, 2026

Warning

Rate limit exceeded

@datlechin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1f8dff86-1df0-406b-81b7-98461c564a19

📥 Commits

Reviewing files that changed from the base of the PR and between 6c3da7d and 2332b31.

📒 Files selected for processing (19)
  • CHANGELOG.md
  • CLAUDE.md
  • TablePro/Core/ChangeTracking/SQLStatementGenerator.swift
  • TablePro/Core/Database/DatabaseDriver.swift
  • TablePro/Core/Plugins/PluginManager.swift
  • TablePro/Core/Services/Infrastructure/DeeplinkHandler.swift
  • TablePro/Core/Storage/ConnectionStorage.swift
  • TablePro/Core/Utilities/Connection/ConnectionURLFormatter.swift
  • TablePro/Core/Utilities/SQL/SQLParameterInliner.swift
  • TablePro/Models/Connection/DatabaseConnection.swift
  • TablePro/Theme/Theme.swift
  • TablePro/ViewModels/DatabaseSwitcherViewModel.swift
  • TablePro/Views/Connection/ConnectionFormView.swift
  • TablePro/Views/Export/ExportDialog.swift
  • TablePro/Views/Main/Extensions/MainContentCoordinator+Navigation.swift
  • TablePro/Views/Structure/TypePickerContentView.swift
  • TableProTests/Models/DatabaseTypeMSSQLTests.swift
  • TableProTests/Models/DatabaseTypeRedisTests.swift
  • TableProTests/Models/DatabaseTypeTests.swift
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/open-database-type-struct
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@datlechin datlechin force-pushed the feat/open-database-type-struct branch from 5d00c5d to 2332b31 Compare March 13, 2026 02:55
@datlechin datlechin merged commit 23cdac8 into main Mar 13, 2026
2 checks passed
@datlechin datlechin deleted the feat/open-database-type-struct branch March 13, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant