Spaces:
Paused
Paused
Download scripts/scratch/test-migrations.ts from igorkurgin/omniroute: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/igorkurgin/omniroute/resolve/main/scripts/scratch/test-migrations.ts
- Command line
-
hf download hf://spaces/igorkurgin/omniroute/scripts/scratch/test-migrations.ts
-
curl -L -o test-migrations.ts https://huggingface.co/spaces/igorkurgin/omniroute/resolve/main/scripts/scratch/test-migrations.ts
1.23 kB
| 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) | |
| ); | |