|
|
@ -521,9 +521,18 @@ export async function runMigrations<T>( |
|
|
|
// Update any old migration names to new ones
|
|
|
|
for (const [oldName, newName] of migrationNameMap) { |
|
|
|
try { |
|
|
|
await sqlExec("UPDATE migrations SET name = ? WHERE name = ?", [newName, oldName]); |
|
|
|
if (await sqlQuery("SELECT 1 FROM migrations WHERE name = ? LIMIT 1", [newName])) { |
|
|
|
migrationLog(`🔄 [Migration] Renamed migration: ${oldName} → ${newName}`); |
|
|
|
await sqlExec("UPDATE migrations SET name = ? WHERE name = ?", [ |
|
|
|
newName, |
|
|
|
oldName, |
|
|
|
]); |
|
|
|
if ( |
|
|
|
await sqlQuery("SELECT 1 FROM migrations WHERE name = ? LIMIT 1", [ |
|
|
|
newName, |
|
|
|
]) |
|
|
|
) { |
|
|
|
migrationLog( |
|
|
|
`🔄 [Migration] Renamed migration: ${oldName} → ${newName}`, |
|
|
|
); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
// Ignore errors - migration might not exist
|
|
|
@ -594,21 +603,35 @@ export async function runMigrations<T>( |
|
|
|
migrationLog(`🔧 [Migration] Executing SQL for: ${migration.name}`); |
|
|
|
migrationLog(`🔧 [Migration] SQL content: ${migration.sql}`); |
|
|
|
const execResult = await sqlExec(migration.sql); |
|
|
|
migrationLog(`🔧 [Migration] SQL execution result: ${JSON.stringify(execResult)}`); |
|
|
|
migrationLog( |
|
|
|
`🔧 [Migration] SQL execution result: ${JSON.stringify(execResult)}`, |
|
|
|
); |
|
|
|
|
|
|
|
// Debug: Check if active_identity table exists and has data
|
|
|
|
if (migration.name === "003_active_identity_and_seed_backup") { |
|
|
|
try { |
|
|
|
const tableCheck = await sqlQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='active_identity'"); |
|
|
|
migrationLog(`🔍 [Migration] Table check result: ${JSON.stringify(tableCheck)}`); |
|
|
|
const tableCheck = await sqlQuery( |
|
|
|
"SELECT name FROM sqlite_master WHERE type='table' AND name='active_identity'", |
|
|
|
); |
|
|
|
migrationLog( |
|
|
|
`🔍 [Migration] Table check result: ${JSON.stringify(tableCheck)}`, |
|
|
|
); |
|
|
|
|
|
|
|
const rowCount = await sqlQuery("SELECT COUNT(*) as count FROM active_identity"); |
|
|
|
migrationLog(`🔍 [Migration] Row count in active_identity: ${JSON.stringify(rowCount)}`); |
|
|
|
const rowCount = await sqlQuery( |
|
|
|
"SELECT COUNT(*) as count FROM active_identity", |
|
|
|
); |
|
|
|
migrationLog( |
|
|
|
`🔍 [Migration] Row count in active_identity: ${JSON.stringify(rowCount)}`, |
|
|
|
); |
|
|
|
|
|
|
|
const allRows = await sqlQuery("SELECT * FROM active_identity"); |
|
|
|
migrationLog(`🔍 [Migration] All rows in active_identity: ${JSON.stringify(allRows)}`); |
|
|
|
migrationLog( |
|
|
|
`🔍 [Migration] All rows in active_identity: ${JSON.stringify(allRows)}`, |
|
|
|
); |
|
|
|
} catch (error) { |
|
|
|
migrationLog(`❌ [Migration] Debug query failed: ${JSON.stringify(error)}`); |
|
|
|
migrationLog( |
|
|
|
`❌ [Migration] Debug query failed: ${JSON.stringify(error)}`, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|