migrate_course_sys/scripts/check-migrations.mjs
Glore Zeng d76623f59d
Some checks failed
build / build (push) Has been cancelled
feat: migrate course content start time and series price
2026-10-19 22:47:31 +08:00

16 lines
831 B
JavaScript

import { readdirSync, readFileSync } from 'node:fs';
import assert from 'node:assert/strict';
const files = readdirSync('.').filter(f => f.endsWith('.sql')).sort();
assert(files.length > 0, 'No migrations');
const versions = new Set();
for (const file of files) {
const match = /^(\d+)_([a-z0-9_]+)\.(up|down)\.sql$/.exec(file);
assert(match, `Invalid migration filename: ${file}`);
const key = `${match[1]}:${match[3]}`;
assert(!versions.has(key), `Duplicate version and direction: ${file}`);
versions.add(key);
if (match[3] === 'down') assert(files.includes(`${match[1]}_${match[2]}.up.sql`), `Missing matching up migration: ${file}`);
assert(readFileSync(file, 'utf8').trim(), `Empty migration: ${file}`);
}
console.log(`${files.length} migration files checked (structure only; MySQL execution still required).`);