Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Summary

Migrates Apple Watch complications from Realm to GRDB database. All existing complications are automatically migrated on first app launch after update. New complications are saved directly to GRDB.

Changes:

  • Created WatchComplicationGRDB struct with all functionality from Realm-based WatchComplication
  • Added automatic migration in WatchComplicationTable.createIfNeeded() that copies all Realm complications to GRDB on first launch
  • Updated all complication access points to use GRDB:
    • iOS: ComplicationListViewController, ComplicationEditViewController, ComplicationFamilySelectViewController
    • watchOS: ComplicationController, ExtensionDelegate
    • API: WatchHelpers, WebhookResponseUpdateComplications
  • Added orphan cleanup that migrates complications with nil/invalid server IDs to first available server
  • Removed WatchComplication from LegacyModelManager Realm cleanup
  • Added GRDB tests, kept legacy Realm tests for compatibility
  • Fixed SwiftFormat lint issues (trailing spaces, line wrapping, extension access control)
  • Added new GRDB files to Xcode project build configuration

Migration Flow:

// In WatchComplicationTable.createIfNeeded()
if !db.tableExists(GRDBDatabaseTable.watchComplication.rawValue) {
    // Create table
    try db.create(table: GRDBDatabaseTable.watchComplication.rawValue) { ... }
    
    // Migrate from Realm
    let realmComplications = Current.realm().objects(WatchComplication.self)
    let grdbComplications = realmComplications.map { WatchComplicationGRDB(from: $0) }
    try grdbComplications.forEach { try $0.insert(db) }
}

Screenshots

N/A - Backend change with no UI impact

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

  • Original Realm WatchComplication model remains untouched for migration period
  • All complications synced between iOS and watchOS now use GRDB
  • Safe fallbacks implemented for edge cases (empty template arrays, nil server IDs)
  • New GRDB files (WatchComplicationGRDB.swift, WatchComplicationGRDB+Queries.swift, WatchComplicationTable.swift) are properly registered in Xcode project's build configuration
Original prompt

Create a migration for apple watch complications, moving them from Realm database to GRDB database. All nee complications should also be directly added to GRDB


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Create migration for apple watch complications to GRDB Migrate Apple Watch complications from Realm to GRDB Dec 7, 2025
Copilot AI requested a review from bgoncal December 7, 2025 15:44
Copilot finished work on behalf of bgoncal December 7, 2025 15:44
@bgoncal
Copy link
Member

bgoncal commented Dec 7, 2025

@copilot Fix lint issues:

Running SwiftFormat...
(lint mode - no files will be changed.)
/home/runner/work/iOS/iOS/Sources/Shared/API/WatchHelpers.swift:29:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/Extensions/Watch/Complication/ComplicationController.swift:21:1: warning: (wrapSingleLineComments) Wrap single line // comments that exceed the specified --maxwidth.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:4:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:6:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:13:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:22:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:31:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:40:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:47:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:54:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:63:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:65:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:65:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:83:1: warning: (extensionAccessControl) Configure the placement of an extension's access control keyword.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB+Queries.swift:83:1: warning: (wrap) Wrap lines that exceed the specified maximum width.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:42:1: warning: (wrap) Wrap lines that exceed the specified maximum width.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1003:1: warning: (blankLinesAroundMark) Insert blank line before and after MARK: comments.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1014:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1021:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1039:1: warning: (redundantSelf) Insert/remove explicit self where applicable.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1041:1: warning: (redundantSelf) Insert/remove explicit self where applicable.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1042:1: warning: (redundantSelf) Insert/remove explicit self where applicable.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1043:1: warning: (redundantSelf) Insert/remove explicit self where applicable.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1044:1: warning: (redundantSelf) Insert/remove explicit self where applicable.
/home/runner/work/iOS/iOS/Sources/Shared/API/Models/WatchComplicationGRDB.swift:1045:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/App/Settings/AppleWatch/ComplicationListViewController.swift:160:1: warning: (trailingSpace) Remove trailing space at end of a line.
/home/runner/work/iOS/iOS/Sources/App/Settings/AppleWatch/ComplicationListViewController.swift:183:1: warning: (wrap) Wrap lines that exceed the specified maximum width.
/home/runner/work/iOS/iOS/Sources/App/Settings/AppleWatch/ComplicationEditViewController.swift:100:1: warning: (trailingSpace) Remove trailing space at end of a line.
SwiftFormat completed in 6.63s.
Source input did not pass lint check.
6/824 files require formatting, 102 files skipped.

Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot Fix lint issues:

Running SwiftFormat...

...

Fixed all SwiftFormat lint issues in commit 16b7ca6:

  • Removed trailing spaces
  • Wrapped long lines to comply with max width
  • Changed to public extension for better access control placement
  • Added blank line before MARK comment
  • Removed redundant self keywords

Copilot finished work on behalf of bgoncal December 7, 2025 21:06
@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

⚠️ SwiftLint disabled in this PR

The following added lines contain // swiftlint:disable. Please verify this is necessary.

@bgoncal
Copy link
Member

bgoncal commented Dec 7, 2025

@copilot fix tests:

<!DOCTYPE html><head></head>
testProcess completed with exit code 1.
--
test: Sources/Shared/API/Webhook/Networking/WebhookResponseUpdateComplications.swift#L27cannot find type 'WatchComplicationGRDB' in scope
test: Sources/Shared/API/Webhook/Networking/WebhookResponseUpdateComplications.swift#L27cannot find type 'WatchComplicationGRDB' in scope
test: Sources/Shared/API/WatchHelpers.swift#L109cannot find 'WatchComplicationGRDB' in scope
test: Sources/Shared/API/WatchHelpers.swift#L107cannot find type 'WatchComplicationGRDB' in scope
test: Sources/Shared/Database/GRDB+Initialization.swift#L55cannot find 'WatchComplicationTable' in scope
test: Sources/Shared/API/Webhook/Networking/WebhookResponseUpdateComplications.swift#L27cannot find type 'WatchComplicationGRDB' in scope

[test](https://github.com/home-assistant/iOS/actions/runs/20010313100/job/57378964286#step:8:11841)
Process completed with exit code 1.
[test: Sources/Shared/API/Webhook/Networking/WebhookResponseUpdateComplications.swift#L27](https://github.com/home-assistant/iOS/pull/4058/files#annotation_42629218091)
cannot find type 'WatchComplicationGRDB' in scope
[test: Sources/Shared/API/Webhook/Networking/WebhookResponseUpdateComplications.swift#L27](https://github.com/home-assistant/iOS/pull/4058/files#annotation_42629218093)
cannot find type 'WatchComplicationGRDB' in scope
[test: Sources/Shared/API/WatchHelpers.swift#L109](https://github.com/home-assistant/iOS/pull/4058/files#annotation_42629218094)
cannot find 'WatchComplicationGRDB' in scope
[test: Sources/Shared/API/WatchHelpers.swift#L107](https://github.com/home-assistant/iOS/pull/4058/files#annotation_42629218095)
cannot find type 'WatchComplicationGRDB' in scope
[test: Sources/Shared/Database/GRDB+Initialization.swift#L55](https://github.com/home-assistant/iOS/pull/4058/files#annotation_42629218097)
cannot find 'WatchComplicationTable' in scope
[test: Sources/Shared/API/Webhook/Networking/WebhookResponseUpdateComplications.swift#L27](https://github.com/home-assistant/iOS/pull/4058/files#annotation_42629218098)
cannot find type 'WatchComplicationGRDB' in scope

Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot fix tests:

...

Fixed build errors in commit 241ac53. The new GRDB files (WatchComplicationGRDB.swift, WatchComplicationGRDB+Queries.swift, and WatchComplicationTable.swift) weren't included in the Xcode project file. Added them to:

  • Models and Tables groups for organization
  • PBXFileReference section for file tracking
  • PBXSourcesBuildPhase for both Shared target build phases

All types should now be in scope and the build should succeed.

Copilot finished work on behalf of bgoncal December 7, 2025 21:34
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.

2 participants