forked from jsnbuchanan/crowd-funder-for-time-pwa
104 lines
3.0 KiB
TypeScript
104 lines
3.0 KiB
TypeScript
import migrationService from "../services/migrationService";
|
|
import type { QueryExecResult } from "../services/migrationService";
|
|
|
|
// Each migration can include multiple SQL statements (with semicolons)
|
|
const MIGRATIONS = [
|
|
{
|
|
name: "001_initial",
|
|
// see ../db/tables files for explanations of the fields
|
|
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 TABLE IF NOT EXISTS secret (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
secret TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS settings (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
accountDid TEXT,
|
|
activeDid TEXT,
|
|
apiServer TEXT,
|
|
filterFeedByNearby BOOLEAN,
|
|
filterFeedByVisible BOOLEAN,
|
|
finishedOnboarding BOOLEAN,
|
|
firstName TEXT,
|
|
hideRegisterPromptOnNewContact BOOLEAN,
|
|
isRegistered BOOLEAN,
|
|
lastName TEXT,
|
|
lastAckedOfferToUserJwtId TEXT,
|
|
lastAckedOfferToUserProjectsJwtId TEXT,
|
|
lastNotifiedClaimId TEXT,
|
|
lastViewedClaimId TEXT,
|
|
notifyingNewActivityTime TEXT,
|
|
notifyingReminderMessage TEXT,
|
|
notifyingReminderTime TEXT,
|
|
partnerApiServer TEXT,
|
|
passkeyExpirationMinutes INTEGER,
|
|
profileImageUrl TEXT,
|
|
searchBoxes TEXT, -- Stored as JSON string
|
|
showContactGivesInline BOOLEAN,
|
|
showGeneralAdvanced BOOLEAN,
|
|
showShortcutBvc BOOLEAN,
|
|
vapid TEXT,
|
|
warnIfProdServer BOOLEAN,
|
|
warnIfTestServer BOOLEAN,
|
|
webPushServer TEXT
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_settings_accountDid ON settings(accountDid);
|
|
|
|
CREATE TABLE IF NOT EXISTS contacts (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
did TEXT NOT NULL,
|
|
name TEXT,
|
|
contactMethods TEXT, -- Stored as JSON string
|
|
nextPubKeyHashB64 TEXT,
|
|
notes TEXT,
|
|
profileImageUrl TEXT,
|
|
publicKeyBase64 TEXT,
|
|
seesMe BOOLEAN,
|
|
registered BOOLEAN
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_did ON contacts(did);
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_name ON contacts(name);
|
|
|
|
CREATE TABLE IF NOT EXISTS logs (
|
|
date TEXT PRIMARY KEY,
|
|
message TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS temp (
|
|
id TEXT PRIMARY KEY,
|
|
blobB64 TEXT
|
|
);
|
|
`,
|
|
},
|
|
];
|
|
|
|
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);
|
|
}
|