diff --git a/db/migrations/migrate.js b/db/migrations/migrate.js deleted file mode 100644 index 6fa2029..0000000 --- a/db/migrations/migrate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** - * Migration Runner for better-sqlite3 - * I know there are external libs out there, but - * a) most of them are pretty bloated - * b) I wanted to have something that fit's this limited use-case - * c) I was searching for justifications anyway to build a migration system on my own. Don't judge me ;) - * - * Executes all migration files in db/migrations/sql in natural order. - * Each migration runs in its own transaction. If a migration fails, only that - * migration is rolled back and the process stops with a non-zero exit code. - * Already applied migrations are skipped using the schema_migrations table. - * - * Usage: - * CLI: yarn run migratedb - * Programmatic: - * import { runMigrations } from './db/migrations/migrate.js'; - * await runMigrations(); - * - * Migration file format (example: db/migrations/sql/1.add-users.js): - * export function up(db) { - * db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)"); - * } - * - */ -import fs from 'fs'; -import path from 'path'; -import {pathToFileURL} from 'url'; -import crypto from 'crypto'; -import SqliteConnection from '../../lib/services/storage/SqliteConnection.js'; -import logger from '../../lib/services/logger.js'; - -const ROOT = path.resolve('.'); -const MIGRATIONS_DIR = path.join(ROOT, 'db', 'migrations', 'sql'); - -/** - * Ensures that the given directory exists, creating it recursively if needed. - * @param {string} p - Path to the directory. - */ -function ensureDir(p) { - if (!fs.existsSync(p)) fs.mkdirSync(p, {recursive: true}); -} - -/** - * Lists all migration files in the migrations directory. - * Migration files must follow the format: .