fix: Resolve database migration issues and consolidate 003 migrations

- Fix $getActiveIdentity() logic flow preventing false "empty table" warnings
- Implement auto-selection of first account when activeDid is null after migration
- Consolidate 003 and 003b migrations into single 003 migration
- Re-introduce foreign key constraint for activeDid referential integrity
- Add comprehensive debug logging for migration troubleshooting
- Remove 003b validation logic and update migration name mapping

Fixes migration from master to active_did_redux branch and ensures system
always has valid activeDid for proper functionality.
This commit is contained in:
Matthew Raymer
2025-09-11 05:07:23 +00:00
parent 6da9e14b8a
commit 616bef655a
3 changed files with 115 additions and 10 deletions

View File

@@ -145,17 +145,25 @@ const MIGRATIONS = [
id INTEGER PRIMARY KEY CHECK (id = 1),
activeDid TEXT DEFAULT NULL, -- NULL instead of empty string
lastUpdated TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (activeDid) REFERENCES accounts(did) ON DELETE RESTRICT
FOREIGN KEY (activeDid) REFERENCES accounts(did) ON DELETE SET NULL
);
-- Add performance indexes
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'));
-- Seed singleton row (only if not already exists)
-- Use a more explicit approach to ensure the row gets inserted
INSERT INTO active_identity (id, activeDid, lastUpdated)
SELECT 1, NULL, datetime('now')
WHERE NOT EXISTS (SELECT 1 FROM active_identity WHERE id = 1);
-- Add hasBackedUpSeed field to settings (from registration-prompt-parity)
-- Add hasBackedUpSeed field to settings (consolidated from 003b)
-- This may fail if column already exists from master branch migration
-- The error handling will catch this and mark migration as applied
ALTER TABLE settings ADD COLUMN hasBackedUpSeed BOOLEAN DEFAULT FALSE;
-- Debug: Verify the row was inserted
SELECT 'DEBUG: Row count after insertion' as debug_message, COUNT(*) as row_count FROM active_identity;
`,
},
];