refactor: consolidate active identity migrations 004-006 into single migration
- Consolidate migrations 004, 005, and 006 into single 004_active_identity_management - Remove redundant migrations 005 (constraint_fix) and 006 (settings_cleanup) - Implement security-first approach with ON DELETE RESTRICT constraint from start - Include comprehensive data migration from settings.activeDid to active_identity.activeDid - Add proper cleanup of orphaned settings records and legacy activeDid values - Update migrationService.ts validation logic to reflect consolidated structure - Fix migration name references and enhance validation for hasBackedUpSeed column - Reduce migration complexity from 3 separate operations to 1 atomic operation - Maintain data integrity with foreign key constraints and performance indexes Migration successfully tested on web platform with no data loss or corruption. Active DID properly migrated: did:ethr:0xCA26A3959D32D2eB5459cE08203DbC4e62e79F5D Files changed: - src/db-sql/migration.ts: Consolidated 3 migrations into 1 (-46 lines) - src/services/migrationService.ts: Updated validation logic (+13 lines)
This commit is contained in:
@@ -374,7 +374,7 @@ async function validateMigrationApplication<T>(
|
||||
} else {
|
||||
validation.hasExpectedColumns = true;
|
||||
}
|
||||
} else if (migration.name === "003_active_identity_and_seed_backup") {
|
||||
} else if (migration.name === "004_active_identity_management") {
|
||||
// Validate active_identity table exists and has correct structure
|
||||
const activeIdentityExists = await validateTableExists(
|
||||
"active_identity",
|
||||
@@ -409,6 +409,8 @@ async function validateMigrationApplication<T>(
|
||||
}
|
||||
|
||||
// Check that hasBackedUpSeed column exists in settings table
|
||||
// Note: This validation is included here because migration 004 is consolidated
|
||||
// and includes the functionality from the original migration 003
|
||||
const hasBackedUpSeedExists = await validateColumnExists(
|
||||
"settings",
|
||||
"hasBackedUpSeed",
|
||||
@@ -493,7 +495,7 @@ async function isSchemaAlreadyPresent<T>(
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
} else if (migration.name === "004_active_identity_and_seed_backup") {
|
||||
} else if (migration.name === "004_active_identity_management") {
|
||||
// Check if active_identity table exists and has correct structure
|
||||
try {
|
||||
// Check that active_identity table exists
|
||||
@@ -515,7 +517,15 @@ async function isSchemaAlreadyPresent<T>(
|
||||
await sqlQuery(
|
||||
`SELECT id, activeDid, lastUpdated FROM active_identity LIMIT 1`,
|
||||
);
|
||||
return true;
|
||||
|
||||
// Also check that hasBackedUpSeed column exists in settings
|
||||
// This is included because migration 004 is consolidated
|
||||
try {
|
||||
await sqlQuery(`SELECT hasBackedUpSeed FROM settings LIMIT 1`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user