Skip to content

Fail CI on new triggers, functions, rules and foreign keys - #9812

Merged
TheSentinel454 merged 3 commits into
mainfrom
elrond/buzz-730-schema-object-lint
Nov 20, 2026
Merged

TheSentinel454 merged 3 commits into
mainfrom
elrond/buzz-730-schema-object-lint

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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 that. This PR adds the guard.

  • Migration lint. migrations_after_retirement_add_no_triggers_functions_or_foreign_keys scans each migration numbered after 0104. It fails on CREATE [OR REPLACE] FUNCTION | PROCEDURE | TRIGGER | RULE, CREATE CONSTRAINT TRIGGER, CREATE EVENT TRIGGER, REFERENCES and FOREIGN KEY, outside -- comments. The error names the file and line, for example migrations/0105_probe.sql:2: CREATE OR REPLACE FUNCTION. Nested /* */ comments are skipped. Quoted identifiers and string values are data, except a string passed to EXECUTE or format(. Each dollar-quoted body is scanned as SQL up to its closing delimiter, so DDL run through EXECUTE in a DO block is caught, and an apostrophe inside $$...$$ cannot hide the rest of the file. It runs in the infra-free buzz-db --lib unit lane.
  • Schema file check. desired_state_schema_layout_is_complete_and_schemabot_shaped allows schema/ files only under tables/public/, types/, partitions/ and seeds/, and runs the same scan on every file. A functions/ or triggers/ file, or an inline REFERENCES in a table file, fails it.
  • Catalog check. admin_schema_parity_between_desired_state_and_migrations now asserts that both bootstrap paths (pgschema + reconcile, and all migrations) have zero non-internal triggers, event triggers, public functions 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 to 0106 or later. The two open ones (#9621 and #9690) add no forbidden object.

What got simpler

  • The parity test's per-table trigger comparisons (events, event_mentions, and the five tables 0096 unguarded) and its separate foreign-key check are replaced by one zero-object assertion.
  • The scoped-key lint no longer parses foreign keys. None may exist, so checking that they lead with community_id is dead logic.
  • schema/schema.sql drops its empty -- functions and -- triggers sections. Its header and docs/database.md stop describing functions/ and triggers/ 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)

  • Phase: none. Test and docs change only. No migration and no runtime code.
  • No trigger, function, procedure, rule or foreign key is added.
  • No migration mutates rows.
  • Rule 4 locations: no schema change. schema/schema.sql changes 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 at 0fed6b1b. 9749e618 adds dollar-quote, nested EXECUTE $tag$ and $1 cases to schema_object_lint_reports_each_construct_with_its_line, and CI checks it.

  • cargo fmt --check and cargo clippy -p buzz-db --all-targets -D warnings: pass.
  • cargo test -p buzz-db --lib and cargo nextest run -p buzz-db --lib: 223 passed.
  • scripts/postgres-test-run.sh for admin_schema_parity_between_desired_state_and_migrations, migrated_catalog_retires_universal_fences_but_keeps_deletion_guards and pgschema_reapply_keeps_runtime_partitions: 3 passed.
  • Proof the lint can fail: a temporary migrations/0105_probe.sql with a function and a REFERENCES column fails the lint with migrations/0105_probe.sql:2: CREATE OR REPLACE FUNCTION and migrations/0105_probe.sql:3: REFERENCES.
  • Proof the catalog check can fail: a temporary 0105 that creates probe() fails the parity test with the migrations leave a trigger, function, rule or foreign key, left: ["function probe()"].
  • The catalog on main at 9c0bcd62, with all 104 migrations applied through psql, has no triggers, functions, foreign keys, rules or event triggers.

🤖 Generated with Claude Code

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>
@TheSentinel454
TheSentinel454 marked this pull request as ready for review November 20, 2026 18:52
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 51b0ea62be7a05a2e268e00c0e4f3dad1d772d33...9749e61843660c9639eee149b62063a6dcc2e33c.
A new review must complete for this exact range. When manual authorization
is required, a user with write access must comment exactly
@buzz-security-review 9749e61843660c9639eee149b62063a6dcc2e33c to authorize a new review.
Any previous review applies only to its recorded range.

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>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026

@wpfleger96 wpfleger96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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 in desired_state_schema_layout_is_complete_and_schemabot_shaped. Its Testing section names b7254f90 and 65022baa, but 0fed6b1b rewrote the tokenizer after that. And 0105 is now taken on main, so open migration PRs need 0106 or later.

Comment thread crates/buzz-db/src/runtime/migration.rs Resolved
Comment thread crates/buzz-db/src/runtime/migration.rs Resolved
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>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
@TheSentinel454
TheSentinel454 merged commit af8287d into main Nov 20, 2026
91 checks passed
@TheSentinel454
TheSentinel454 deleted the elrond/buzz-730-schema-object-lint branch November 20, 2026 20:56

This branch was successfully deployed

1 active deployment
codex-review — 9749e618 Deployed Nov 20, 2026 by TheSentinel454 via Run Codex Security Review #16897
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants