|
@ -188,19 +188,19 @@ export async function runMigrations<T>( |
|
|
sqlQuery: (sql: string, params?: unknown[]) => Promise<T>, |
|
|
sqlQuery: (sql: string, params?: unknown[]) => Promise<T>, |
|
|
extractMigrationNames: (result: T) => Set<string>, |
|
|
extractMigrationNames: (result: T) => Set<string>, |
|
|
): Promise<void> { |
|
|
): Promise<void> { |
|
|
logger.info("[Migration] Starting database migrations"); |
|
|
logger.debug("[Migration] Starting database migrations"); |
|
|
|
|
|
|
|
|
for (const migration of MIGRATIONS) { |
|
|
for (const migration of MIGRATIONS) { |
|
|
logger.debug("[Migration] Registering migration:", migration.name); |
|
|
logger.debug("[Migration] Registering migration:", migration.name); |
|
|
registerMigration(migration); |
|
|
registerMigration(migration); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
logger.info("[Migration] Running migration service"); |
|
|
logger.debug("[Migration] Running migration service"); |
|
|
await runMigrationsService(sqlExec, sqlQuery, extractMigrationNames); |
|
|
await runMigrationsService(sqlExec, sqlQuery, extractMigrationNames); |
|
|
logger.info("[Migration] Database migrations completed"); |
|
|
logger.debug("[Migration] Database migrations completed"); |
|
|
|
|
|
|
|
|
// Bootstrapping: Ensure active account is selected after migrations
|
|
|
// Bootstrapping: Ensure active account is selected after migrations
|
|
|
logger.info("[Migration] Running bootstrapping hooks"); |
|
|
logger.debug("[Migration] Running bootstrapping hooks"); |
|
|
try { |
|
|
try { |
|
|
// Check if we have accounts but no active selection
|
|
|
// Check if we have accounts but no active selection
|
|
|
const accountsResult = await sqlQuery("SELECT COUNT(*) FROM accounts"); |
|
|
const accountsResult = await sqlQuery("SELECT COUNT(*) FROM accounts"); |
|
@ -218,7 +218,7 @@ export async function runMigrations<T>( |
|
|
: null; |
|
|
: null; |
|
|
|
|
|
|
|
|
if (accountsCount > 0 && (!activeDid || activeDid === "")) { |
|
|
if (accountsCount > 0 && (!activeDid || activeDid === "")) { |
|
|
logger.info("[Migration] Auto-selecting first account as active"); |
|
|
logger.debug("[Migration] Auto-selecting first account as active"); |
|
|
const firstAccountResult = await sqlQuery( |
|
|
const firstAccountResult = await sqlQuery( |
|
|
"SELECT did FROM accounts ORDER BY dateCreated, did LIMIT 1", |
|
|
"SELECT did FROM accounts ORDER BY dateCreated, did LIMIT 1", |
|
|
); |
|
|
); |
|
|