refactor(db): restructure migrations to preserve master compatibility

- Split consolidated migration into 3 separate migrations
- Preserve master's 001_initial and 002_add_iViewContent structure
- Move active_identity creation to new 003_active_identity_and_seed_backup
- Add hasBackedUpSeed field from registration-prompt-parity branch
- Remove activeDid performance index for simplified migration
- Maintain foreign key constraints and smart deletion pattern
- Remove unused $getAllAccountDids method from PlatformServiceMixin

This restructure ensures backward compatibility with master branch
while adding advanced features (active_identity table, seed backup
tracking) in a clean, maintainable migration sequence.
This commit is contained in:
Matthew Raymer
2025-09-09 06:13:25 +00:00
parent 72872935ae
commit e1cf27be05
2 changed files with 28 additions and 25 deletions

View File

@@ -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'))
);
`,
},
];