MCPcopy
hub / github.com/nowork-studio/NotFair / applyMigrations

Function applyMigrations

notfair-cmo/src/server/db/db.ts:34–59  ·  view source on GitHub ↗
(db: Database.Database)

Source from the content-addressed store, hash-verified

32}
33
34function applyMigrations(db: Database.Database): void {
35 db.exec(`
36 CREATE TABLE IF NOT EXISTS _migrations (
37 name TEXT PRIMARY KEY,
38 applied_at TEXT NOT NULL
39 );
40 `);
41
42 const applied = new Set(
43 (db.prepare("SELECT name FROM _migrations").all() as { name: string }[]).map(
44 (row) => row.name,
45 ),
46 );
47
48 for (const migration of MIGRATIONS) {
49 if (applied.has(migration.name)) continue;
50 const tx = db.transaction(() => {
51 db.exec(migration.sql);
52 db.prepare("INSERT INTO _migrations (name, applied_at) VALUES (?, ?)").run(
53 migration.name,
54 new Date().toISOString(),
55 );
56 });
57 tx();
58 }
59}

Callers 1

getDbFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected