File size: 1,228 Bytes
35743bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import Database from "better-sqlite3";
import { runMigrations, getMigrationStatus } from "../../src/lib/db/migrationRunner.js";

const db = new Database("/tmp/test-migrations.sqlite");
db.exec(
  "CREATE TABLE _omniroute_migrations (version TEXT PRIMARY KEY, name TEXT NOT NULL, applied_at TEXT NOT NULL DEFAULT (datetime('now')))"
);

const fakeApplied = [
  "001",
  "002",
  "003",
  "004",
  "005",
  "006",
  "007",
  "008",
  "009",
  "010",
  "011",
  "012",
  "013",
  "014",
  "015",
  "016",
  "017",
  "018",
  "019",
  "020",
  "021",
];
for (const v of fakeApplied) {
  db.prepare("INSERT INTO _omniroute_migrations (version, name) VALUES (?, ?)").run(v, "fake_" + v);
}
db.prepare("INSERT INTO _omniroute_migrations (version, name) VALUES (?, ?)").run(
  "026",
  "call_logs_cache_source"
);
db.prepare("INSERT INTO _omniroute_migrations (version, name) VALUES (?, ?)").run(
  "029",
  "provider_connection_max_concurrent"
);

console.log(
  "Status before:",
  getMigrationStatus(db).pending.map((p) => p.version)
);
try {
  runMigrations(db, { isNewDb: false });
} catch (e: any) {
  console.error("Error:", e.message);
}
console.log(
  "Status after:",
  getMigrationStatus(db).pending.map((p) => p.version)
);