mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
fix(db): refuse to regenerate a frozen Postgres baseline and check its trigger ports once frozen
gen:pg-baseline rewrote the baseline with its cut at the newest migration on disk, so after a migration landed after the cut, running it moved the cut over that migration while Postgres installs created from the old baseline would still run it through the migrator. It now refuses while a migration follows the committed cut, names those migrations and the routine, and moves the cut only with --move-cut (lint:dialect keeps such a migration under the post-cut rules either way). check:pg-baseline stopped comparing SQLite triggers with POSTGRES_TRIGGERS once the baseline was frozen, so a trigger a later migration created on SQLite went unnoticed. The comparison now runs in both states, with advice that points at the migration when the baseline is frozen.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
import {
|
||||
checkBaseline,
|
||||
cutMoveRefusal,
|
||||
postCutMigrations,
|
||||
rowStatements,
|
||||
triggerPortProblems,
|
||||
@@ -98,13 +99,27 @@ describe('checkBaseline', () => {
|
||||
expect(checkBaseline(sample, generated(C, [A, B, C]), false, PORTED)).toEqual([]);
|
||||
});
|
||||
|
||||
it('PGBASE-013: while not frozen, a SQLite trigger without a port is reported; once frozen the triggers are not checked', () => {
|
||||
it('PGBASE-013: a SQLite trigger without a port is reported, before the cut and once frozen alike', () => {
|
||||
const withNewTrigger = [...PORTED, 'trg_new_trigger'];
|
||||
expect(checkBaseline(sample, generated(B, [A, B]), true, withNewTrigger)).toEqual([
|
||||
"SQLite triggers without a Postgres port in POSTGRES_TRIGGERS: trg_new_trigger. Add each one's function and " +
|
||||
'trigger to src/db/engine/postgres/postgres-triggers.ts, then run npm run gen:pg-baseline.',
|
||||
]);
|
||||
expect(checkBaseline(sample, generated(C, [A, B, C]), false, withNewTrigger)).toEqual([]);
|
||||
// A post-cut migration that left a trigger on SQLite alone: frozen, the
|
||||
// baseline is not regenerated, so the advice points at the migration.
|
||||
const frozen = checkBaseline(sample, generated(C, [A, B, C]), false, withNewTrigger);
|
||||
expect(frozen).toHaveLength(1);
|
||||
expect(frozen[0]).toContain('SQLite triggers without a Postgres port in POSTGRES_TRIGGERS: trg_new_trigger.');
|
||||
expect(frozen[0]).toContain('do its work in the repository instead');
|
||||
expect(frozen[0]).not.toContain('gen:pg-baseline');
|
||||
});
|
||||
|
||||
it('PGBASE-015: rewriting a frozen baseline is refused, naming the migrations after its cut and --move-cut', () => {
|
||||
expect(cutMoveRefusal(sample, [A, B])).toBeNull();
|
||||
const refusal = cutMoveRefusal(sample, [A, B, C]);
|
||||
expect(refusal).toContain(`the baseline is frozen at ${B}, and 1 migration(s) follow its cut: ${C}.`);
|
||||
expect(refusal).toContain('npm run gen:pg-migration');
|
||||
expect(refusal).toContain('npm run gen:pg-baseline -- --move-cut');
|
||||
});
|
||||
|
||||
it('PGBASE-012: a manifest naming a migration that is gone, or missing one before its cut, is reported', () => {
|
||||
@@ -146,6 +161,14 @@ describe('triggerPortProblems', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('PGBASE-022: once frozen, the advice goes to the migration after the cut, not to a regenerated baseline', () => {
|
||||
const [missing, stale] = triggerPortProblems(['a', 'b'], ['a', 'c'], true);
|
||||
expect(missing).toContain('SQLite triggers without a Postgres port in POSTGRES_TRIGGERS: b.');
|
||||
expect(missing).toContain('take it out of the migration');
|
||||
expect(stale).toContain('POSTGRES_TRIGGERS ports triggers the migrations no longer create: c.');
|
||||
expect(stale).toContain('in the postgres member of its engineDdl call');
|
||||
});
|
||||
|
||||
it('PGBASE-021: the committed baseline carries every trigger port after the tables', () => {
|
||||
const statements = readPostgresBaseline().statements;
|
||||
const firstTrigger = statements.findIndex((statement) => statement.startsWith('CREATE FUNCTION'));
|
||||
|
||||
Reference in New Issue
Block a user