fix Capacitor to use the same migrations (migrations run but accounts aren't created)

This commit is contained in:
2025-06-04 22:01:14 -06:00
parent 705c6092a3
commit 8e57692387
6 changed files with 96 additions and 270 deletions

View File

@@ -100,10 +100,27 @@ class AbsurdSqlDatabaseService implements DatabaseService {
// An error is thrown without this pragma: "File has invalid page size. (the first block of a new file must be written first)"
await this.db.exec(`PRAGMA journal_mode=MEMORY;`);
const sqlExec = this.db.exec.bind(this.db);
const sqlExec = this.db.run.bind(this.db);
const sqlQuery = this.db.exec.bind(this.db);
// Extract the migration names for the absurd-sql format
const extractMigrationNames: (result: QueryExecResult[]) => Set<string> = (
result,
) => {
const queryResult = result as QueryExecResult[];
// Even with the "select name" query, the QueryExecResult may be [] (which doesn't make sense to me).
if (queryResult.length > 0) {
const singleResult = queryResult[0];
const executedMigrations: Set<string> = new Set(
singleResult.values.map((row) => row[0] as string),
);
return executedMigrations;
}
return new Set();
};
// Run migrations
await runMigrations(sqlExec);
await runMigrations(sqlExec, sqlQuery, extractMigrationNames);
this.initialized = true;