diff --git a/src/db-sql/migration.ts b/src/db-sql/migration.ts index 8d653897..b8f1a113 100644 --- a/src/db-sql/migration.ts +++ b/src/db-sql/migration.ts @@ -36,15 +36,11 @@ const MIGRATIONS = [ { name: "001_initial", sql: ` - -- Enable foreign key constraints for data integrity - PRAGMA foreign_keys = ON; - - -- Create accounts table with UNIQUE constraint on did CREATE TABLE IF NOT EXISTS accounts ( id INTEGER PRIMARY KEY AUTOINCREMENT, dateCreated TEXT NOT NULL, derivationPath TEXT, - did TEXT NOT NULL UNIQUE, -- UNIQUE constraint for foreign key support + did TEXT NOT NULL, identityEncrBase64 TEXT, -- encrypted & base64-encoded mnemonicEncrBase64 TEXT, -- encrypted & base64-encoded passkeyCredIdHex TEXT, @@ -106,8 +102,7 @@ const MIGRATIONS = [ profileImageUrl TEXT, publicKeyBase64 TEXT, seesMe BOOLEAN, - registered BOOLEAN, - iViewContent BOOLEAN DEFAULT TRUE + registered BOOLEAN ); CREATE INDEX IF NOT EXISTS idx_contacts_did ON contacts(did); @@ -122,12 +117,23 @@ const MIGRATIONS = [ id TEXT PRIMARY KEY, blobB64 TEXT ); + `, + }, + { + name: "002_add_iViewContent_to_contacts", + sql: ` + ALTER TABLE contacts ADD COLUMN iViewContent BOOLEAN DEFAULT TRUE; + `, + }, + { + name: "003_active_identity_and_seed_backup", + sql: ` + -- Enable foreign key constraints for data integrity + PRAGMA foreign_keys = ON; + + -- Add UNIQUE constraint to accounts.did for foreign key support + CREATE UNIQUE INDEX IF NOT EXISTS idx_accounts_did_unique ON accounts(did); - CREATE TABLE IF NOT EXISTS migrations ( - name TEXT PRIMARY KEY, - applied_at TEXT NOT NULL DEFAULT (datetime('now')) - ); - -- Create active_identity table with foreign key constraint CREATE TABLE IF NOT EXISTS active_identity ( id INTEGER PRIMARY KEY CHECK (id = 1), @@ -137,12 +143,20 @@ const MIGRATIONS = [ ); -- Add performance indexes - CREATE INDEX IF NOT EXISTS idx_active_identity_activeDid ON active_identity(activeDid); CREATE UNIQUE INDEX IF NOT EXISTS idx_active_identity_single_record ON active_identity(id); -- Seed singleton row INSERT INTO active_identity (id, activeDid, lastUpdated) VALUES (1, NULL, datetime('now')); - `, + + -- Add hasBackedUpSeed field to settings (from registration-prompt-parity) + ALTER TABLE settings ADD COLUMN hasBackedUpSeed BOOLEAN DEFAULT FALSE; + + -- Create migrations tracking table + CREATE TABLE IF NOT EXISTS migrations ( + name TEXT PRIMARY KEY, + applied_at TEXT NOT NULL DEFAULT (datetime('now')) + ); + `, }, ]; diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index ca7b5e24..77b5a98a 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -741,17 +741,6 @@ export const PlatformServiceMixin = { // SMART DELETION PATTERN DAL METHODS // ================================================= - /** - * Get all account DIDs ordered by creation date - * Required for smart deletion pattern - */ - async $getAllAccountDids(): Promise { - const result = await this.$dbQuery( - "SELECT did FROM accounts ORDER BY dateCreated, did", - ); - return result?.values?.map((row) => row[0] as string) || []; - }, - /** * Get account DID by ID * Required for smart deletion pattern