Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(migrations): registered_via CHECK added NOT VALID, then validated

time-attacke2dedabffcae
diff --git a/src/core/schema-migrations/v233-oauth-client-registered-via.ts b/src/core/schema-migrations/v233-oauth-client-registered-via.ts
index ac4b0b6d2d..55f944db1e 100644
--- a/src/core/schema-migrations/v233-oauth-client-registered-via.ts
+++ b/src/core/schema-migrations/v233-oauth-client-registered-via.ts
@@ -6,13 +6,19 @@ import type { Migration } from './types.ts';
// read-only consent. No index and no backfill: only new DCR registrations
// write 'dcr'. Migration-only like min_trust (trust-tiers): fresh installs get
// the column from this migration too, so an upgraded brain and a fresh one end
-// with the same column order.
+// with the same column order. The CHECK is added NOT VALID (no scan under the
+// ADD) and validated separately, the trust-tiers pattern for this table.
export const v233: Migration = {
version: 233,
name: 'oauth_client_registered_via',
idempotent: true,
sql: `
- ALTER TABLE oauth_clients ADD COLUMN IF NOT EXISTS registered_via TEXT
- CHECK (registered_via IN ('dcr'));
+ ALTER TABLE oauth_clients ADD COLUMN IF NOT EXISTS registered_via TEXT;
+ DO $do$ BEGIN
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'oauth_clients_registered_via_check' AND conrelid = 'oauth_clients'::regclass) THEN
+ ALTER TABLE oauth_clients ADD CONSTRAINT oauth_clients_registered_via_check CHECK (registered_via IN ('dcr')) NOT VALID;
+ END IF;
+ END $do$;
+ ALTER TABLE oauth_clients VALIDATE CONSTRAINT oauth_clients_registered_via_check;
`,
};
diff --git a/test/e2e/oauth-client-registered-via-postgres.test.ts b/test/e2e/oauth-client-registered-via-postgres.test.ts
index e416c190b0..e4cc85acac 100644
--- a/test/e2e/oauth-client-registered-via-postgres.test.ts
+++ b/test/e2e/oauth-client-registered-via-postgres.test.ts
@@ -73,7 +73,7 @@ describePg('oauth_client_registered_via migration on Postgres (#6202)', () => {
expect(await editable(clientId)).toBe(false);
await oldServerInsert('pre-migration-example');
} finally {
- await engine.executeRaw(migration.sql);
+ await engine.runMigration(migration.version, migration.sql);
}
expect(await hasColumn()).toBe(true);
});
@@ -81,7 +81,7 @@ describePg('oauth_client_registered_via migration on Postgres (#6202)', () => {
test('rows from before the migration stay NULL and read-only; a repeat run changes nothing', async () => {
expect(await marker('pre-migration-example')).toBeNull();
expect(await editable('pre-migration-example')).toBe(false);
- await engine.executeRaw(migration.sql);
+ await engine.runMigration(migration.version, migration.sql);
expect(await marker('pre-migration-example')).toBeNull();
});
diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.json
index c34eecf346..c39d3ec64e 100644
--- a/test/fixtures/goldens/migrations/records.json
+++ b/test/fixtures/goldens/migrations/records.json
@@ -3498,8 +3498,8 @@
"idempotent": true,
"name": "oauth_client_registered_via",
"sql": {
- "length": 119,
- "sha256": "13fc89cb57e1c37195c776b832dbec7c5180b0be8a6e881406fe3280b09c066c"
+ "length": 489,
+ "sha256": "5767fc58a79405b9ff3bbcc291a988f42e6f41553a1bbf062c132b3306f04ba3"
},
"sqlFor": "absent",
"transaction": "absent",
diff --git a/test/oauth-client-registered-via-migration.test.ts b/test/oauth-client-registered-via-migration.test.ts
index 9ce2af9284..be1e27fd27 100644
--- a/test/oauth-client-registered-via-migration.test.ts
+++ b/test/oauth-client-registered-via-migration.test.ts
@@ -69,7 +69,7 @@ describe('oauth_client_registered_via migration (#6202)', () => {
expect(await editable(clientId)).toBe(false);
await oldServerInsert('pre-migration-example');
} finally {
- await engine.executeRaw(migration.sql);
+ await engine.runMigration(migration.version, migration.sql);
}
expect(await hasColumn()).toBe(true);
});
@@ -77,7 +77,7 @@ describe('oauth_client_registered_via migration (#6202)', () => {
test('rows from before the migration stay NULL and read-only; a repeat run changes nothing', async () => {
expect(await marker('pre-migration-example')).toBeNull();
expect(await editable('pre-migration-example')).toBe(false);
- await engine.executeRaw(migration.sql);
+ await engine.runMigration(migration.version, migration.sql);
expect(await marker('pre-migration-example')).toBeNull();
});