launch-migration.test.mjs 1.1 KB

123456
  1. import {test} from 'node:test';import assert from 'node:assert/strict';import {PGlite} from '@electric-sql/pglite';
  2. import {withoutTransactionWrapper,launchMigrationSql} from '../lib/launch-migration.mjs';
  3. test('standalone SQL transaction wrappers cannot commit part of the release',async()=>{
  4. const db=new PGlite();try{await assert.rejects(db.transaction(async tx=>{await tx.exec('CREATE TABLE release_first(id int)');await tx.exec(withoutTransactionWrapper('BEGIN;\nCREATE TABLE release_middle(id int);\nCOMMIT;'));await tx.exec('SELECT release_deliberate_missing_function()');}),/does not exist/);const r=await db.query("SELECT tablename FROM pg_tables WHERE tablename IN ('release_first','release_middle')");assert.equal(r.rows.length,0);}finally{await db.close();}
  5. });
  6. test('prepared release SQL has no top-level transaction boundary and keeps routine bodies',async()=>{const sql=await launchMigrationSql();assert(!/^(BEGIN|COMMIT);\s*$/m.test(sql));for(const fn of ['xs_credential_guard','xs_payroll_command','xs_payroll_cutoff_confirm','xs_process_deletion'])assert(sql.includes('FUNCTION '+fn));});