fix: simplify active_identity migration to resolve iOS SQLite failures
The complex table rewrite approach in migration 003_active_did_separation was failing on iOS SQLite, causing "no such table: active_identity" errors. The migration was being marked as applied despite validation failures. Changes: - Simplify migration SQL to only create active_identity table and migrate data - Remove complex table rewrite that was failing on iOS SQLite versions - Remove foreign key constraint that could cause compatibility issues - Update validation logic to focus on active_identity table existence only - Remove validation check for activeDid column removal from settings table This approach is more reliable across different SQLite versions and platforms while maintaining the core functionality of separating activeDid into its own table for better database architecture. Fixes iOS build database errors and ensures migration completes successfully.
This commit is contained in:
@@ -280,6 +280,40 @@ async function validateMigrationApplication<T>(
|
||||
error,
|
||||
);
|
||||
}
|
||||
} else if (migration.name === "003_active_did_separation") {
|
||||
// Validate active_identity table exists and has correct structure
|
||||
try {
|
||||
// Check that active_identity table exists
|
||||
const activeIdentityResult = await sqlQuery(
|
||||
`SELECT name FROM sqlite_master WHERE type='table' AND name='active_identity'`,
|
||||
);
|
||||
const hasActiveIdentityTable =
|
||||
(activeIdentityResult as unknown as { values: unknown[][] })?.values?.length > 0 ||
|
||||
(Array.isArray(activeIdentityResult) && activeIdentityResult.length > 0);
|
||||
|
||||
if (!hasActiveIdentityTable) {
|
||||
validation.isValid = false;
|
||||
validation.errors.push(`Table active_identity missing`);
|
||||
}
|
||||
|
||||
// Check that active_identity has the expected structure
|
||||
try {
|
||||
await sqlQuery(`SELECT id, activeDid, lastUpdated FROM active_identity LIMIT 1`);
|
||||
validation.hasExpectedColumns = true;
|
||||
} catch (error) {
|
||||
validation.isValid = false;
|
||||
validation.errors.push(`active_identity table missing expected columns`);
|
||||
}
|
||||
|
||||
validation.tableExists = hasActiveIdentityTable;
|
||||
} catch (error) {
|
||||
validation.isValid = false;
|
||||
validation.errors.push(`Validation error for active_did_separation: ${error}`);
|
||||
logger.error(
|
||||
`❌ [Migration-Validation] Validation failed for ${migration.name}:`,
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add validation for future migrations here
|
||||
@@ -343,6 +377,35 @@ async function isSchemaAlreadyPresent<T>(
|
||||
// Reduced logging - only log on error
|
||||
return false;
|
||||
}
|
||||
} else if (migration.name === "003_active_did_separation") {
|
||||
// Check if active_identity table exists and has correct structure
|
||||
try {
|
||||
// Check that active_identity table exists
|
||||
const activeIdentityResult = await sqlQuery(
|
||||
`SELECT name FROM sqlite_master WHERE type='table' AND name='active_identity'`,
|
||||
);
|
||||
const hasActiveIdentityTable =
|
||||
(activeIdentityResult as unknown as { values: unknown[][] })?.values?.length > 0 ||
|
||||
(Array.isArray(activeIdentityResult) && activeIdentityResult.length > 0);
|
||||
|
||||
if (!hasActiveIdentityTable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that active_identity has the expected structure
|
||||
try {
|
||||
await sqlQuery(`SELECT id, activeDid, lastUpdated FROM active_identity LIMIT 1`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`🔍 [Migration-Schema] Schema check failed for ${migration.name}, assuming not present:`,
|
||||
error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add schema checks for future migrations here
|
||||
|
||||
Reference in New Issue
Block a user