Phase 3 of the cross-project sqlite-migrate adoption — port nanodrop to
consume bchen-sqlite-migrate@v0.1.0. Replaces the inline db.exec(...)
block in src/db/schema.ts with applyMigrations(db, MIGRATIONS_DIR,
{ genesisProbeTable: 'users' }).
The genesis-probe (table 'users' exists) handles pre-existing prod DBs
automatically — first deploy after merge stamps 0001_init as applied
without re-executing, subsequent boots are no-ops.
Adds three npm scripts (db:migrate, db:status, db:stamp) and a
byte-stability test pinning sha256(0001_init.sql) so the migration is
treated as immutable history.
19 lines
677 B
TypeScript
19 lines
677 B
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { createHash } from 'node:crypto';
|
|
import { resolve } from 'node:path';
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
const EXPECTED_0001_SHA256 =
|
|
'34f092b4bb8544a48acfee0fad08d51b1b75fedf4ffdfbcb790d2656d0f1d57a';
|
|
|
|
describe('migrations byte stability', () => {
|
|
it('0001_init.sql sha256 is frozen — edit means new migration, not edit-in-place', () => {
|
|
const body = readFileSync(
|
|
resolve(import.meta.dirname, '..', '..', 'src', 'db', 'migrations', '0001_init.sql'),
|
|
'utf8',
|
|
);
|
|
const actual = createHash('sha256').update(body).digest('hex');
|
|
expect(actual).toBe(EXPECTED_0001_SHA256);
|
|
});
|
|
});
|