Skip to content

Add local database mirror for ServerManager persistence#4472

Open
bgoncal wants to merge 4 commits intomainfrom
sync-server-info-database
Open

Add local database mirror for ServerManager persistence#4472
bgoncal wants to merge 4 commits intomainfrom
sync-server-info-database

Conversation

@bgoncal
Copy link
Copy Markdown
Member

@bgoncal bgoncal commented Apr 2, 2026

Summary

Introduce a GRDB-backed sanitized mirror for ServerManager so non-secret server metadata can be recovered if Keychain entries are lost (e.g. during developer-account migration). Key changes:

  • Add ServerManagerPersistence.swift: defines ServerManagerKeychain and ServerManagerMirrorStore protocols and Keychain-backed implementations/adapters.
  • Add ServerManagerMirrorStore.swift: GRDB-backed ServerManagerGRDBMirrorStore that persists sanitized ServerInfo records.
  • Add ServerInfoMirrorTable.swift and register the new serverInfoMirror table in GRDB initialization and DatabaseTables.
  • Extend ServerInfo with mirroredForPersistence and mirrorPlaceholderToken to ensure secrets (tokens, webhook URLs, client certs) are stripped before persistence.
  • Update ServerManagerImpl to use a mirrorStore: persist sanitized mirrors alongside Keychain, merge mirror+Keychain when reading (prefer Keychain), sync mirror on setup, and keep mirror in sync on add/remove/removeAll.

This ensures the app can restore server shells without exposing secrets outside the Keychain, while keeping Keychain as the source of truth.

Screenshots

Link to pull request in Documentation repository

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

Any other notes

Copy link
Copy Markdown
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

Adds a GRDB-backed “mirror” persistence layer for ServerManager so non-secret server metadata can be recovered if Keychain entries are lost (e.g., during developer account migration), while keeping Keychain as the source of truth for secrets.

Changes:

  • Introduces ServerManagerMirrorStore + GRDB implementation and a new serverInfoMirror table to persist sanitized ServerInfo.
  • Updates ServerManagerImpl to keep Keychain + mirror in sync, and to fall back to the mirror when Keychain entries are missing.
  • Extends ServerInfo with sanitization helpers and updates unit tests/DB schema tests to cover the new table and mirror behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Tests/Shared/ServerManager.test.swift Adds a fake mirror store and tests for backfill/fallback/precedence behavior.
Tests/Shared/Database/TableSchemaTests.test.swift Adds schema validation for ServerInfoMirrorTable and updates total table count.
Tests/Shared/Database/GRDB+Initialization.test.swift Updates initialization expectations to include the new table and new total count.
Tests/Shared/Database/DatabaseTableProtocol.test.swift Adds conformance test for ServerInfoMirrorTable and updates total table count.
Sources/Shared/Database/Tables/ServerInfoMirrorTable.swift Defines the GRDB table schema for the mirror store.
Sources/Shared/Database/GRDB+Initialization.swift Registers the new table in DatabaseQueue.tables().
Sources/Shared/Database/DatabaseTables.swift Adds serverInfoMirror table name + column enum.
Sources/Shared/API/ServerManagerPersistence.swift Extracts Keychain/mirror persistence protocols and Keychain helpers.
Sources/Shared/API/ServerManagerMirrorStore.swift Implements GRDB-backed mirror persistence (ServerManagerGRDBMirrorStore).
Sources/Shared/API/ServerManager.swift Integrates mirror store into ServerManagerImpl (sync, fallback reads, merged listing).
Sources/Shared/API/Server.swift Adds mirroredForPersistence and placeholder token used for sanitized persistence.
HomeAssistant.xcodeproj/project.pbxproj Adds new source files to the Xcode project.

Copy link
Copy Markdown
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

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