import { test, before, after } from "node:test"; import assert from "node:assert/strict"; import { runMigrations } from "../db/migrate.ts"; import { pool } from "../db/pool.ts"; import { dropSchema } from "./helpers.ts"; // Parte de un esquema vacío a propósito: la aserción es que el bootstrap se // aplica, y eso solo es cierto sobre una base sin migrar. before(async () => { await dropSchema(); }); after(async () => { await pool.end(); }); test("runMigrations aplica los archivos pendientes y es idempotente", async () => { const first = await runMigrations(); assert.ok(first.includes("000_bootstrap.sql"), "debe aplicar el bootstrap"); assert.ok(first.includes("001_core.sql"), "debe aplicar el núcleo"); const second = await runMigrations(); assert.deepEqual(second, [], "una segunda corrida no aplica nada"); const { rows } = await pool.query( `SELECT count(*)::int AS c FROM schema_migrations WHERE filename = '000_bootstrap.sql'` ); assert.equal(rows[0].c, 1, "no debe registrarse dos veces"); });