Skip to content

feat: Exclude constraints and triggers#434

Merged
dwirz merged 10 commits intomainfrom
next
Mar 6, 2026
Merged

feat: Exclude constraints and triggers#434
dwirz merged 10 commits intomainfrom
next

Conversation

@nickredmark
Copy link
Contributor

No description provided.

- Filter extension-owned functions from getDatabaseFunctions (excludes btree_gist etc)
- Improve CHECK constraint normalization for semantic comparison (strip redundant parens)
- Skip btree_gist CREATE EXTENSION when already installed

Made-with: Cursor
Add normalizeSqlIdentifiers so (deleted = true) and ("deleted" = true) compare equal.
Prevents spurious DROP/ADD for period-related CHECK constraints when schema matches.

Made-with: Cursor
- Use Unicode placeholder to avoid identifier regex corrupting string literals
- Store raw def for EXCLUDE/trigger down migrations (normalized only for comparison)
- Strip parens from OR/AND operands so (a) OR (b) matches a OR b
- Strip schema prefix from trigger def (ON public.table -> ON table)

Made-with: Cursor
…gration

- Canonicalize type aliases (timestamp with time zone -> timestamptz)
- Strip redundant parens in WHERE clause via findMatchingParen
- Fix normalizeSqlIdentifiers double-quoting (placeholder for quoted idents)
- Add unit test for equivalent EXCLUDE def normalization

Made-with: Cursor
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🎉 This PR is included in version 23.8.0-next.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🎉 This PR is included in version 23.8.0-next.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

- **`name`**: A short name for the constraint (used in migration constraint names).
- **`expression`**: A PostgreSQL boolean expression. Column names **must** be double-quoted (e.g. `"score"`) so they are validated against the model’s columns; unquoted identifiers are not checked.
- **`expression`**: A PostgreSQL boolean expression. Column names **must** be double-quoted (e.g. `"score"`) so they are validated against the model’s columns.
- **`message`** (optional): Human-readable message for when the constraint fails. Not used by graphql-magic; available for application-level error mapping.
Copy link
Member

Choose a reason for hiding this comment

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

in type message is not optional

const constraintName = this.getConstraintName(model, entry, i);
up.push(() => {
this.addCheckConstraint(table, constraintName, expression);
this.addConstraintTrigger(table, constraintName, entry);
Copy link
Member

Choose a reason for hiding this comment

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

The docs say "The function must be defined in functions.ts", but this isn't enforced at generation time. If a user typos the function name, they'll only discover the error when the migration runs against Postgres. A validation step (checking parsedFunctions for the referenced function name) would catch this earlier.

@dwirz dwirz merged commit 133c65a into main Mar 6, 2026
13 checks passed
@dwirz dwirz deleted the next branch March 6, 2026 09:55
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

🎉 This PR is included in version 23.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants