forked from trent_larson/crowd-funder-for-time-pwa
chore: a couple missed files
This commit is contained in:
@@ -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 rowCount = await sqlQuery("SELECT COUNT(*) as count FROM active_identity");
|
||||
migrationLog(`🔍 [Migration] Row count in active_identity: ${JSON.stringify(rowCount)}`);
|
||||
|
||||
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 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)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -673,25 +673,25 @@ export const PlatformServiceMixin = {
|
||||
logger.debug(
|
||||
"[PlatformServiceMixin] Active identity is null (initial state), attempting auto-selection",
|
||||
);
|
||||
|
||||
|
||||
// Try to auto-select first available account
|
||||
const availableAccounts = await this.$dbQuery(
|
||||
"SELECT did FROM accounts ORDER BY dateCreated, did LIMIT 1",
|
||||
);
|
||||
|
||||
|
||||
if (availableAccounts?.values?.length) {
|
||||
const firstAccountDid = availableAccounts.values[0][0] as string;
|
||||
logger.debug(
|
||||
"[PlatformServiceMixin] Auto-selecting first account as active:",
|
||||
{ firstAccountDid },
|
||||
);
|
||||
|
||||
|
||||
// Update active_identity table with the first account
|
||||
await this.$dbExec(
|
||||
"UPDATE active_identity SET activeDid = ?, lastUpdated = datetime('now') WHERE id = 1",
|
||||
[firstAccountDid],
|
||||
);
|
||||
|
||||
|
||||
logger.debug(
|
||||
"[PlatformServiceMixin] Active identity auto-selected successfully",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user