add DB setup with migrations

This commit is contained in:
2025-05-25 11:06:30 -06:00
parent a48a122224
commit c14c2d173e
6 changed files with 185 additions and 31 deletions

38
src/db-sql/migration.ts Normal file
View File

@@ -0,0 +1,38 @@
import migrationService from '../services/migrationService';
import type { QueryExecResult } from '../services/migrationService';
const MIGRATIONS = [
{
name: '001_create_accounts_table',
// see ../db/tables files for explanations
sql: `
CREATE TABLE IF NOT EXISTS accounts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
dateCreated TEXT NOT NULL,
derivationPath TEXT,
did TEXT NOT NULL,
identity TEXT,
mnemonic TEXT,
passkeyCredIdHex TEXT,
publicKeyHex TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_accounts_did ON accounts(did);
CREATE INDEX IF NOT EXISTS idx_accounts_publicKeyHex ON accounts(publicKeyHex);
`
}
];
export async function registerMigrations(): Promise<void> {
// Register all migrations
for (const migration of MIGRATIONS) {
await migrationService.registerMigration(migration);
}
}
export async function runMigrations(
sqlExec: (sql: string, params?: any[]) => Promise<Array<QueryExecResult>>
): Promise<void> {
await registerMigrations();
await migrationService.runMigrations(sqlExec);
}