Skip to content

Abstract column migration logic into DatabaseTableProtocol for all tables#4243

Merged
bgoncal merged 7 commits intomainfrom
copilot/update-table-creation-logic
Jan 22, 2026
Merged

Abstract column migration logic into DatabaseTableProtocol for all tables#4243
bgoncal merged 7 commits intomainfrom
copilot/update-table-creation-logic

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

Summary

Table migration logic for adding new columns and removing obsolete columns has been abstracted into DatabaseTableProtocol with a default implementation. All 13 table implementations now conform to the extended protocol and support automatic column migration.

Protocol Changes:

  • Added tableName: String property requirement
  • Added definedColumns: [String] property requirement
  • Added default migrateColumns(database:) implementation that handles adding/removing columns

Updated Tables:
All tables now implement the protocol and support column migration:

  • HAppEntityTable, WatchConfigTable, CarPlayConfigTable, AssistPipelinesTable
  • AppEntityRegistryListForDisplayTable, AppEntityRegistryTable, AppDeviceRegistryTable
  • AppPanelTable, CustomWidgetTable, AppAreaTable
  • HomeViewConfigurationTable, CameraListConfigurationTable, AssistConfigurationTable

Column Enums:
All column enums in DatabaseTables now conform to CaseIterable for consistent migration support.

Relies on ALTER TABLE ... DROP COLUMN support (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 tableName and definedColumns, and the shared migrateColumns(database:) method handles the actual column synchronization.

Original prompt

In GRDB+Initialization.swift each tablet has a logic to create table columns that may not exist when the user updates the app, update those table creationg to also delete columns that are not defined in the create method anymore


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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 AI changed the title [WIP] Update table creation logic to delete obsolete columns Add logic to delete obsolete columns during GRDB table migration Jan 20, 2026
Copilot AI requested a review from bgoncal January 20, 2026 15:20
@bgoncal
Copy link
Member

bgoncal commented Jan 21, 2026

@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>
Copy link
Contributor Author

Copilot AI commented Jan 21, 2026

@copilot Abstract this columns addition and deletion into DatabaseTableProtocol and enforce conformance by all children

Done in ea51c62. Added tableName and definedColumns properties to DatabaseTableProtocol with a default migrateColumns(database:) implementation. All 13 tables now conform to the extended protocol and use the shared migration logic.

Copilot AI changed the title Add logic to delete obsolete columns during GRDB table migration Abstract column migration logic into DatabaseTableProtocol for all tables Jan 21, 2026
@bgoncal bgoncal marked this pull request as ready for review January 22, 2026 09:02
Copilot AI review requested due to automatic review settings January 22, 2026 09:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DatabaseTableProtocol with tableName, definedColumns, and a default migrateColumns(database:) implementation.
  • Updated all table implementations to provide schema metadata and call migrateColumns when the table already exists.
  • Updated DatabaseTables column enums to conform to CaseIterable to 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.

bgoncal and others added 2 commits January 22, 2026 10:16
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 60.55046% with 43 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@0553c44). Learn more about missing BASE report.

Files with missing lines Patch % Lines
Sources/Shared/Database/GRDB+Initialization.swift 0.00% 14 Missing ⚠️
...urces/Shared/Database/AppEntityRegistryTable.swift 44.44% 5 Missing ⚠️
...urces/Shared/Database/AppDeviceRegistryTable.swift 66.66% 2 Missing ⚠️
.../Tables/AppEntityRegistryListForDisplayTable.swift 66.66% 2 Missing ⚠️
Sources/Shared/Database/Tables/AppPanelTable.swift 66.66% 2 Missing ⚠️
...red/Database/Tables/AssistConfigurationTable.swift 85.71% 2 Missing ⚠️
.../Shared/Database/Tables/AssistPipelinesTable.swift 66.66% 2 Missing ⚠️
...Database/Tables/CameraListConfigurationTable.swift 66.66% 2 Missing ⚠️
...es/Shared/Database/Tables/CarPlayConfigTable.swift 66.66% 2 Missing ⚠️
...ces/Shared/Database/Tables/CustomWidgetTable.swift 85.71% 2 Missing ⚠️
... and 4 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal bgoncal merged commit 7647dde into main Jan 22, 2026
15 checks passed
@bgoncal bgoncal deleted the copilot/update-table-creation-logic branch January 22, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants