-
Notifications
You must be signed in to change notification settings - Fork 403
Migrate zone management from Realm to GRDB #4060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/migrate-zones-to-grdb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Created AppZone struct with GRDB support - Created AppZoneTable and AppZone+Queries - Updated DatabaseTables enum with zone columns - Registered AppZoneTable in GRDB initialization - Created migration function from Realm to GRDB - Updated LegacyModelManager to sync zones to GRDB - Migrated ZoneManager to use GRDB zones instead of Realm - Updated ZoneManager components (Collector, Processor, RegionFilter, AccuracyFuzzer) - Updated HAAPI methods to work with AppZone - Updated WebhookUpdateLocation and WebhookResponseLocation - Added AppZone init overload for LocationHistoryEntry Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
- Integrated AppZoneMigration.migrateFromRealm() into AppDelegate.setupModels() - Updated GeocoderSensor to fetch zones from GRDB instead of Realm - Left LocationHistoryDetailViewController and SettingsDetailViewController with Realm for now (historical data) Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
- Added syncZonesToGRDB helper to test zone updates - Modified addedZones to also save zones to GRDB - Updated test to sync zone modifications and deletions to GRDB - Post ZonesDidUpdate notification after GRDB changes in tests Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
- Added databaseTableName static property to AppZone - Fixed updateInRegion mutating method to update self - Addressed all code review comments Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Migrate zones from Realm to GRDB
Migrate zone management from Realm to GRDB
Dec 7, 2025
Member
|
@copilot fix linting issues: |
- Remove all trailing spaces from affected files - Fix extensionAccessControl warnings by moving access modifiers to extension declarations Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Contributor
Author
Member
|
@copilot fix tests: |
- Added AppZone.swift, AppZone+Queries.swift, AppZoneMigration.swift, and AppZoneTable.swift to project - Added files to Shared-iOS, Shared-watchOS, Tests-Shared, and Tests-App targets - Fixes "cannot find type 'AppZone' in scope" compilation errors Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Contributor
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Migration Plan: Zones from Realm to GRDB
Overview
Successfully migrated zone management from Realm to GRDB to enable eventual removal of Realm dependency from the app.
Implementation Summary
✅ Completed Tasks
1. GRDB Zone Model and Table Structure
AppZonestruct with all zone properties (location, radius, tracking settings, beacons, SSID filters)AppZoneTablefor database table creationGRDBDatabaseTableand columns toDatabaseTablesAppZoneTablein GRDB initializationdatabaseTableNamestatic property for proper table mapping2. Zone Query Methods
AppZone+Queries.swiftwith comprehensive fetch methods:fetchZones(for:)- Get all zones for a serverfetchTrackableZones(for:)- Get trackable zones for a serverfetchAllTrackableZones()- Get all trackable zones across serversfetchZone(id:)andfetchZone(entityId:serverId:)- Get specific zoneszone(of:in:)- Find zone containing a locationsave(_:)- Save zones to databasedeleteZones(for:)anddeleteZone(id:)- Delete zonesupdateInRegion(_:)- Update zone status3. Migration from Realm to GRDB
AppZoneMigration.migrateFromRealm()for one-time migrationAppDelegate.setupModels()4. ZoneManager Migration to GRDB
ZoneManagerto fetch zones from GRDB instead of RealmZonesDidUpdate)ZoneManagerCollectorto fetch zones from GRDBZoneManagerProcessorto use GRDB and update zone status in GRDBZoneManagerRegionFilterto acceptAppZoneinstead ofRLMZoneZoneManagerAccuracyFuzzerclasses to fetch zones from GRDB5. LegacyModelManager Integration
LegacyModelManager.store()to sync zones to GRDB when updating RealmsyncZonesToGRDB()helper methodZonesDidUpdatenotification after GRDB updates6. API and Webhook Updates
HAAPI.zoneStateEvent()to acceptAppZoneHAAPI.SubmitLocation()to useAppZoneWebhookUpdateLocationinitializers forAppZoneWebhookResponseLocationand metadata forAppZoneLocationHistoryEntryinit overload forAppZoneGeocoderSensorto fetch zones from GRDB7. Test Updates
syncZonesToGRDB()helper in ZoneManager testsaddedZones()to sync zones to GRDBZonesDidUpdatenotifications for proper zone manager updates8. Code Quality
Migration Strategy
Dual-Write Approach:
Zero-Downtime Migration:
Technical Implementation
Key Design Decisions:
databaseTableNamefor explicit table mappingTesting Status
Next Steps (for follow-up)
Impact
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.