Abstract column migration logic into DatabaseTableProtocol for all tables#4243
Abstract column migration logic into DatabaseTableProtocol for all tables#4243
Conversation
Updated HAppEntityTable and HomeViewConfigurationTable to remove columns that are no longer defined in the schema when updating existing tables. Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
|
@copilot Abstract this columns addition and deletion into DatabaseTableProtocol and enforce conformance by all children |
- Add tableName and definedColumns properties to DatabaseTableProtocol - Add migrateColumns(database:) default implementation for adding/removing columns - Make all column enums in DatabaseTables conform to CaseIterable - Update all 13 table implementations to use the abstracted migration logic Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Done in ea51c62. Added |
There was a problem hiding this comment.
Pull request overview
Centralizes GRDB table column migration (add missing columns, drop obsolete columns) by extending DatabaseTableProtocol and updating all table implementations to use shared migration logic.
Changes:
- Extended
DatabaseTableProtocolwithtableName,definedColumns, and a defaultmigrateColumns(database:)implementation. - Updated all table implementations to provide schema metadata and call
migrateColumnswhen the table already exists. - Updated
DatabaseTablescolumn enums to conform toCaseIterableto support consistent column enumeration.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/Shared/Database/GRDB+Initialization.swift | Adds protocol requirements and shared column migration implementation (add/drop). |
| Sources/Shared/Database/DatabaseTables.swift | Adds CaseIterable conformance for column enums used by migration. |
| Sources/Shared/Database/Tables/HAppEntityTable.swift | Provides tableName/definedColumns and delegates migrations to the protocol extension. |
| Sources/Shared/Database/Tables/WatchConfigTable.swift | Same: adopts shared migration flow. |
| Sources/Shared/Database/Tables/CarPlayConfigTable.swift | Same: adopts shared migration flow. |
| Sources/Shared/Database/Tables/AssistPipelinesTable.swift | Same: adopts shared migration flow. |
| Sources/Shared/Database/Tables/AppEntityRegistryListForDisplayTable.swift | Same: adopts shared migration flow. |
| Sources/Shared/Database/Tables/AppPanelTable.swift | Same: adopts shared migration flow. |
| Sources/Shared/Database/Tables/CustomWidgetTable.swift | Converts to throwing API and adopts shared migration flow. |
| Sources/Shared/Database/Tables/CameraListConfigurationTable.swift | Same: adopts shared migration flow. |
| Sources/Shared/Database/Tables/AssistConfigurationTable.swift | Switches to existence-check + shared migration approach. |
| Sources/Shared/Environment/AppAreaTable.swift | Adds schema metadata and shared migration invocation. |
| Sources/Shared/Environment/HomeViewConfigurationTable.swift | Replaces per-table “add missing columns” logic with shared migration. |
| Sources/Shared/Database/AppEntityRegistryTable.swift | Adds schema metadata and shared migration invocation. |
| Sources/Shared/Database/AppDeviceRegistryTable.swift | Adds schema metadata and shared migration invocation. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4243 +/- ##
=======================================
Coverage ? 43.21%
=======================================
Files ? 260
Lines ? 14974
Branches ? 0
=======================================
Hits ? 6471
Misses ? 8503
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Table migration logic for adding new columns and removing obsolete columns has been abstracted into
DatabaseTableProtocolwith a default implementation. All 13 table implementations now conform to the extended protocol and support automatic column migration.Protocol Changes:
tableName: Stringproperty requirementdefinedColumns: [String]property requirementmigrateColumns(database:)implementation that handles adding/removing columnsUpdated Tables:
All tables now implement the protocol and support column migration:
HAppEntityTable,WatchConfigTable,CarPlayConfigTable,AssistPipelinesTableAppEntityRegistryListForDisplayTable,AppEntityRegistryTable,AppDeviceRegistryTableAppPanelTable,CustomWidgetTable,AppAreaTableHomeViewConfigurationTable,CameraListConfigurationTable,AssistConfigurationTableColumn Enums:
All column enums in
DatabaseTablesnow conform toCaseIterablefor consistent migration support.Relies on
ALTER TABLE ... DROP COLUMNsupport (SQLite 3.35+, iOS 15+).Screenshots
N/A - Database internals only.
Link to pull request in Documentation repository
N/A - No user-facing changes.
Any other notes
The migration logic is now centralized in the protocol extension, eliminating code duplication across table implementations. Each table provides its
tableNameanddefinedColumns, and the sharedmigrateColumns(database:)method handles the actual column synchronization.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.