Repository navigation
Fail CI on new triggers, functions, rules and foreign keys - #9812
Conversation
Migrations up to 0104 dropped every trigger, function and foreign key. docs/database.md Rules 1 and 2 forbid adding them back, but nothing enforced it. - A lint fails any migration after 0104 that creates a function, procedure, trigger (including constraint and event triggers) or rule, or contains REFERENCES or FOREIGN KEY. It reports file and line. - The desired-state/migration parity test asserts both bootstrap paths have zero such objects. This replaces its per-table trigger and foreign-key comparisons. - The scoped-key lint no longer parses foreign keys, since none may exist. - schema.sql and docs/database.md stop describing functions/ and triggers/ directories that no longer exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
🔐 Codex Security Review
|
Review fixes: - Skip nested /* */ block comments as whitespace. A comment between CREATE and FUNCTION, or inside FOREIGN KEY, no longer hides the construct. - Treat quoted identifiers and string values as data, so a default such as 'references' passes. A string passed to EXECUTE or format( is still checked as SQL, including E'' strings. - The desired-state layout test rejects schema/functions/ and schema/triggers/, allows files only under tables/public/, types/, partitions/ and seeds/, and runs the same check on every schema file. That catches an inline REFERENCES in a table file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
wpfleger96
left a comment
There was a problem hiding this comment.
🤖 No blocking concerns. The lint and the catalog check do what the description says, CI is green, and the branch merges cleanly with current main, including main's new 0105_push_gateway_delivery_request_in_flight.sql, which the lint passes. Three non-blocking notes inline, plus one on the description:
- The description doesn't mention the new
schema/file check indesired_state_schema_layout_is_complete_and_schemabot_shaped. Its Testing section namesb7254f90and65022baa, but0fed6b1brewrote the tokenizer after that. And0105is now taken onmain, so open migration PRs need0106or later.
Review fixes: - Read each $tag$ ... $tag$ body as SQL up to its closing delimiter. An apostrophe inside a dollar-quoted literal, such as COMMENT ... IS $$Owner's id$$, no longer opens a string that hides the rest of the file from the lint. - Drop the schema/functions/ and schema/triggers/ existence loop. The on-disk include check and the directory allowlist already reject files there. Update the layout test's doc comment to match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Summary
Migrations up to
0104dropped every trigger, function and foreign key.docs/database.mdRules 1 and 2 forbid adding them back, but nothing enforced that. This PR adds the guard.migrations_after_retirement_add_no_triggers_functions_or_foreign_keysscans each migration numbered after0104. It fails onCREATE [OR REPLACE] FUNCTION | PROCEDURE | TRIGGER | RULE,CREATE CONSTRAINT TRIGGER,CREATE EVENT TRIGGER,REFERENCESandFOREIGN KEY, outside--comments. The error names the file and line, for examplemigrations/0105_probe.sql:2: CREATE OR REPLACE FUNCTION. Nested/* */comments are skipped. Quoted identifiers and string values are data, except a string passed toEXECUTEorformat(. Each dollar-quoted body is scanned as SQL up to its closing delimiter, so DDL run throughEXECUTEin aDOblock is caught, and an apostrophe inside$$...$$cannot hide the rest of the file. It runs in the infra-freebuzz-db --libunit lane.desired_state_schema_layout_is_complete_and_schemabot_shapedallowsschema/files only undertables/public/,types/,partitions/andseeds/, and runs the same scan on every file. Afunctions/ortriggers/file, or an inlineREFERENCESin a table file, fails it.admin_schema_parity_between_desired_state_and_migrationsnow asserts that both bootstrap paths (pgschema + reconcile, and all migrations) have zero non-internal triggers, event triggers,publicfunctions and procedures, rules and foreign keys. Extension members (pgcrypto) are excluded. No allowlist is needed: main with all 104 migrations applied has none of these objects.Main now has
0105, which passes the lint. Open PRs that add a migration only need to renumber to0106or later. The two open ones (#9621 and #9690) add no forbidden object.What got simpler
events,event_mentions, and the five tables0096unguarded) and its separate foreign-key check are replaced by one zero-object assertion.community_idis dead logic.schema/schema.sqldrops its empty-- functionsand-- triggerssections. Its header anddocs/database.mdstop describingfunctions/andtriggers/directories that no longer exist, and the doc's "remaining triggers stay as a backstop" text now says they are gone.Checklist (
docs/database.md)schema/schema.sqlchanges only comments.Related issue
None found.
Testing
Run on a Linux workstation with PostgreSQL 17 at
b7254f90, before the review fixes. CI passed with the first review fixes at0fed6b1b.9749e618adds dollar-quote, nestedEXECUTE $tag$and$1cases toschema_object_lint_reports_each_construct_with_its_line, and CI checks it.cargo fmt --checkandcargo clippy -p buzz-db --all-targets -D warnings: pass.cargo test -p buzz-db --libandcargo nextest run -p buzz-db --lib: 223 passed.scripts/postgres-test-run.shforadmin_schema_parity_between_desired_state_and_migrations,migrated_catalog_retires_universal_fences_but_keeps_deletion_guardsandpgschema_reapply_keeps_runtime_partitions: 3 passed.migrations/0105_probe.sqlwith a function and aREFERENCEScolumn fails the lint withmigrations/0105_probe.sql:2: CREATE OR REPLACE FUNCTIONandmigrations/0105_probe.sql:3: REFERENCES.0105that createsprobe()fails the parity test withthe migrations leave a trigger, function, rule or foreign key,left: ["function probe()"].9c0bcd62, with all 104 migrations applied through psql, has no triggers, functions, foreign keys, rules or event triggers.🤖 Generated with Claude Code