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:
@@ -36,15 +36,11 @@ const MIGRATIONS = [
|
|||||||
{
|
{
|
||||||
name: "001_initial",
|
name: "001_initial",
|
||||||
sql: `
|
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 (
|
CREATE TABLE IF NOT EXISTS accounts (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
dateCreated TEXT NOT NULL,
|
dateCreated TEXT NOT NULL,
|
||||||
derivationPath TEXT,
|
derivationPath TEXT,
|
||||||
did TEXT NOT NULL UNIQUE, -- UNIQUE constraint for foreign key support
|
did TEXT NOT NULL,
|
||||||
identityEncrBase64 TEXT, -- encrypted & base64-encoded
|
identityEncrBase64 TEXT, -- encrypted & base64-encoded
|
||||||
mnemonicEncrBase64 TEXT, -- encrypted & base64-encoded
|
mnemonicEncrBase64 TEXT, -- encrypted & base64-encoded
|
||||||
passkeyCredIdHex TEXT,
|
passkeyCredIdHex TEXT,
|
||||||
@@ -106,8 +102,7 @@ const MIGRATIONS = [
|
|||||||
profileImageUrl TEXT,
|
profileImageUrl TEXT,
|
||||||
publicKeyBase64 TEXT,
|
publicKeyBase64 TEXT,
|
||||||
seesMe BOOLEAN,
|
seesMe BOOLEAN,
|
||||||
registered BOOLEAN,
|
registered BOOLEAN
|
||||||
iViewContent BOOLEAN DEFAULT TRUE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_contacts_did ON contacts(did);
|
CREATE INDEX IF NOT EXISTS idx_contacts_did ON contacts(did);
|
||||||
@@ -122,12 +117,23 @@ const MIGRATIONS = [
|
|||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
blobB64 TEXT
|
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 active_identity table with foreign key constraint
|
||||||
CREATE TABLE IF NOT EXISTS active_identity (
|
CREATE TABLE IF NOT EXISTS active_identity (
|
||||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||||
@@ -137,12 +143,20 @@ const MIGRATIONS = [
|
|||||||
);
|
);
|
||||||
|
|
||||||
-- Add performance indexes
|
-- 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);
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_active_identity_single_record ON active_identity(id);
|
||||||
|
|
||||||
-- Seed singleton row
|
-- Seed singleton row
|
||||||
INSERT INTO active_identity (id, activeDid, lastUpdated) VALUES (1, NULL, datetime('now'));
|
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'))
|
||||||
|
);
|
||||||
|
`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -741,17 +741,6 @@ export const PlatformServiceMixin = {
|
|||||||
// SMART DELETION PATTERN DAL METHODS
|
// SMART DELETION PATTERN DAL METHODS
|
||||||
// =================================================
|
// =================================================
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all account DIDs ordered by creation date
|
|
||||||
* Required for smart deletion pattern
|
|
||||||
*/
|
|
||||||
async $getAllAccountDids(): Promise<string[]> {
|
|
||||||
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
|
* Get account DID by ID
|
||||||
* Required for smart deletion pattern
|
* Required for smart deletion pattern
|
||||||
|
|||||||
Reference in New Issue
Block a user