forked from jsnbuchanan/crowd-funder-for-time-pwa
add DB setup with migrations
This commit is contained in:
38
src/db-sql/migration.ts
Normal file
38
src/db-sql/migration.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user