Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(bootstrap): strip the deleted_at scope trigger with the column, assert the replay recreates it

garrytan168b93b4bdf1
diff --git a/test/e2e/postgres-bootstrap.test.ts b/test/e2e/postgres-bootstrap.test.ts
index 1bd82b6039..738303c163 100644
--- a/test/e2e/postgres-bootstrap.test.ts
+++ b/test/e2e/postgres-bootstrap.test.ts
@@ -405,6 +405,13 @@ describe.skipIf(skip)('PostgresEngine forward-reference bootstrap (E2E)', () =>
WHERE tablename = 'pages' AND indexname = 'pages_deleted_at_purge_idx'
`;
expect(idx).toHaveLength(1);
+ // The CASCADE dropped the derivation-purge scope trigger with the column;
+ // the replay must recreate it once deleted_at exists again.
+ const trg = await conn`
+ SELECT tgname FROM pg_trigger
+ WHERE tgrelid = 'pages'::regclass AND tgname = 'pages_derivation_scope_delete'
+ `;
+ expect(trg).toHaveLength(1);
}, 60_000);
// Migration v120 — schema-lint hardening (#1647 / #171). Postgres-only
diff --git a/test/schema-bootstrap-coverage.test.ts b/test/schema-bootstrap-coverage.test.ts
index c0216ad9a1..0396d32c67 100644
--- a/test/schema-bootstrap-coverage.test.ts
+++ b/test/schema-bootstrap-coverage.test.ts
@@ -285,6 +285,9 @@ test('applyForwardReferenceBootstrap covers every forward reference declared in
ALTER TABLE content_chunks DROP COLUMN IF EXISTS symbol_name_qualified;
ALTER TABLE content_chunks DROP COLUMN IF EXISTS search_vector;
+ -- The derivation-purge scope trigger fires on UPDATE OF deleted_at; a
+ -- pre-v0.26.5 brain predates it (the schema replay recreates it).
+ DROP TRIGGER IF EXISTS pages_derivation_scope_delete ON pages;
DROP INDEX IF EXISTS pages_deleted_at_purge_idx;
ALTER TABLE pages DROP COLUMN IF EXISTS deleted_at;
@@ -436,6 +439,9 @@ test('after bootstrap, PGLITE_SCHEMA_SQL replays without crashing on missing for
ALTER TABLE links DROP CONSTRAINT IF EXISTS links_from_to_type_source_origin_unique;
ALTER TABLE links DROP COLUMN IF EXISTS link_source;
ALTER TABLE links DROP COLUMN IF EXISTS origin_page_id;
+ -- The derivation-purge scope trigger fires on UPDATE OF deleted_at; a
+ -- pre-v0.26.5 brain predates it (the schema replay recreates it).
+ DROP TRIGGER IF EXISTS pages_derivation_scope_delete ON pages;
DROP INDEX IF EXISTS pages_deleted_at_purge_idx;
ALTER TABLE pages DROP COLUMN IF EXISTS deleted_at;
@@ -485,6 +491,12 @@ test('after bootstrap, PGLITE_SCHEMA_SQL replays without crashing on missing for
const { PGLITE_SCHEMA_SQL } = await import('../src/core/pglite-schema.ts');
await (engine as any).applyForwardReferenceBootstrap();
await db.exec(PGLITE_SCHEMA_SQL);
+
+ // An upgrading brain gets the deleted_at scope trigger once the column exists.
+ const { rows: scopeTrigger } = await db.query(
+ `SELECT 1 FROM pg_trigger WHERE tgrelid = 'pages'::regclass AND tgname = 'pages_derivation_scope_delete'`,
+ );
+ expect(scopeTrigger).toHaveLength(1);
} finally {
await engine.disconnect();
}