Skip to content

Add portable conditional guard triggers - #215

Merged
jogibear9988 merged 1 commit into
masterfrom
codex/209-guard-triggers
Nov 22, 2026
Merged

jogibear9988 merged 1 commit into
masterfrom
codex/209-guard-triggers

Conversation

@jogibear9988

@jogibear9988 jogibear9988 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Adds composable SQL predicates, OLD/NEW bindings, related-row EXISTS guards and fluent create/drop/preview operations. One definition renders native aborting triggers for SQLite, PostgreSQL, SQL Server, MySQL, MariaDB, Oracle, Db2, Firebird, Informix, Sybase ASE and SAP HANA. Ingres remains an explicit implementation gap.

GuardTriggerProviderTests runs the same behaviors on all eleven engines through both direct SQL and the database-independent Insert/Update/Delete/Select APIs: rejection with the domain error, allowed writes, drop/retry, atomic multirow update/delete, null-safe changes and both reparenting directions. Direct-SQL enforcement tests are retained unchanged. The projected multirow insert API enters in #219, which adds its guard conformance test to this same eleven-provider fixture.

SQLite attached-table predicates bind within the subject database while main/TEMP target names remain unambiguous. Provider namespace, native literal, helper cleanup, pairing-key and DDL/version restrictions are documented. Local focused tests pass; GitHub Actions runs the eleven live database suites, including Oracle and HANA.

First PR in https://github.com/dotnetprojects/Migrator.NET/stack/221: #215 → #216 → #217 → #218 → #219 → #220 → #222.

Closes #209.

SQLite exported UPDATE OF clauses are validated against queued/renamed table definitions or the preview's existing-table metadata callback. Missing metadata, schema invalidated by raw SQL, unknown watched columns and unverified implicit rowid aliases fail explicitly. The shared guard/audit export regressions include executing generated scripts and verifying writes through the database-independent APIs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical schema-resolution defects can attach guards to unintended tables or query the wrong related rows, while additional SQL-generation flaws can bypass guards or break migrations.

9 open issues
What changed in this PR

Adds database-enforced conditional write guards to the migration API, addressing issue #209 with composable predicates and provider-specific trigger generation.

Changes:

  • Introduces SQL expressions with OLD/NEW bindings and related-row EXISTS conditions.
  • Adds guard creation, removal, and fluent SQL preview for SQLite, PostgreSQL, SQL Server, and MySQL/MariaDB.
  • Adds provider tests and documents transaction behavior, pairing-key requirements, and concurrency limits.
File Description
src/​Migrator/​Framework/​SqlExpression.cs Defines composable predicates, row bindings, and literal rendering.
src/​Migrator/​Framework/​GuardTrigger.cs Defines guards and generates provider-specific create/drop SQL.
src/​Migrator/​Framework/​Fluent/​TriggerOperations.cs Adds migration operations, validation, reversal, and preview.
src/​Migrator/​Framework/​Fluent/​SchemaBuilders.cs Exposes fluent guard creation and trigger removal.
src/​Migrator.Tests/​PortableTriggerTests.cs Tests multi-row rejection, reparenting, and definition validation.
docs/​portable-schema-api.md Documents usage, provider constraints, and operational limits.

Review effort: Balanced

Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
Comment thread src/Migrator/Framework/SqlExpression.cs Resolved
Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
Comment thread src/Migrator/Framework/SqlExpression.cs Resolved
Comment thread src/Migrator/Framework/SqlExpression.cs Resolved
Comment thread src/Migrator/Framework/SqlExpression.cs Resolved
Comment thread src/Migrator/Framework/SqlExpression.cs Resolved
Copilot AI balanced review requested due to automatic review settings November 22, 2026 07:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical flaws in schema resolution, SQL Server alias handling, and Unicode literals can cause guards to check the wrong data or allow prohibited writes.

10 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Snapshot mutable column arrays for each operation build

src/​Migrator/​Framework/​Fluent/​SchemaBuilders.cs:10

Mutating KeyColumns or UpdateColumns on a built GuardTriggerOperation changes later Preview/Apply calls because every build returns the same operation. This violates the independent-build snapshot behavior tested in src/Migrator.Tests/FluentAuthoringTests.cs:58-74 and :150-170. Keep a private input snapshot and enqueue a factory that clones both arrays for each build.

Review effort: Balanced

Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
Copilot AI balanced review requested due to automatic review settings November 22, 2026 07:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical defects in NULL handling, schema resolution, alias binding, and drop validation can bypass guards, target incorrect tables, or fail migrations after earlier DDL executes.

11 open issues
2 previously missed issues

In code that hasn't changed since last review

High severity Resolve trigger tables using the provider's configured schema

src/​Migrator/​Framework/​GuardTrigger.cs:28

Rendering with only the dialect bypasses the provider's configured default schema: a provider scoped to tenant can create tenant.child through AddTable but install this guard on a different, unqualified child, or fail. The same issue affects drop at GuardTrigger.cs:32 and related-table EXISTS at SqlExpression.cs:40. Use provider-aware table resolution for create, drop, and related-table expressions so all target the configured namespace.

Medium severity Reject SQL Server 2005 for unsupported THROW statements

src/​Migrator/​Framework/​GuardTrigger.cs:61

SqlServer2005Dialect inherits SqlServerDialect, so this support check accepts ProviderTypes.SqlServer2005 and renders THROW statements that SQL Server 2005 cannot execute. This also lets definition validation and preview succeed for an unsupported engine. Reject the legacy dialect explicitly unless a compatible rollback/error implementation is provided.

Review effort: Balanced

Comment thread src/Migrator/Framework/SqlExpression.cs Resolved
@jogibear9988
jogibear9988 added this pull request to stack #221 November 22, 2026 07:33

@jogibear9988 jogibear9988 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed the current head. The actionable findings are inline.

Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
Comment thread src/Migrator/Framework/SqlExpression.cs Resolved

@jogibear9988 jogibear9988 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Follow-up review of the current head. One actionable finding is inline.

Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
@jogibear9988
jogibear9988 force-pushed the codex/209-guard-triggers branch 2 times, most recently from b88ad1b to d02eb62 Compare November 22, 2026 10:33

@jogibear9988 jogibear9988 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Follow-up review of the current head. New findings are inline.

Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
@jogibear9988
jogibear9988 force-pushed the codex/209-guard-triggers branch from d02eb62 to 96aa591 Compare November 22, 2026 11:14

@jogibear9988 jogibear9988 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

One new regression in the SQLite trigger validation is inline.

Comment thread src/Migrator/Framework/GuardTrigger.cs Resolved
@jogibear9988
jogibear9988 force-pushed the codex/209-guard-triggers branch from 96aa591 to ff9f1e0 Compare November 22, 2026 11:30
@jogibear9988
jogibear9988 force-pushed the codex/209-guard-triggers branch from ff9f1e0 to 4c19c71 Compare November 22, 2026 14:37
@jogibear9988
jogibear9988 merged commit c3c255d into master Nov 22, 2026
14 checks passed
@jogibear9988
jogibear9988 deleted the codex/209-guard-triggers branch November 22, 2026 15:44
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.

Add a portable API for conditional guard triggers

2 participants