Skip to content

Support ON UPDATE CASCADE via CascadeOnUpdate attribute#175

Merged
msallin merged 1 commit into
masterfrom
claude/fervent-solomon-9af87c
Jun 16, 2026
Merged

Support ON UPDATE CASCADE via CascadeOnUpdate attribute#175
msallin merged 1 commit into
masterfrom
claude/fervent-solomon-9af87c

Conversation

@msallin

@msallin msallin commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Entity Framework has no concept of update-cascade (it assumes immutable
keys), so the generated DDL only ever emitted ON DELETE CASCADE. Neither
ForeignKeyAttribute nor the fluent API can express ON UPDATE CASCADE.

Add an opt-in CascadeOnUpdateAttribute placed on the dependent foreign
key property. It is registered as a column annotation, survives the EF
model build, and is read back from the store model during SQL generation
to append the ON UPDATE CASCADE clause to the foreign key constraint.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fd93cc27-7444-4103-adfd-3379ab8494c4

📥 Commits

Reviewing files that changed from the base of the PR and between 81f12d5 and c4f47fd.

📒 Files selected for processing (8)
  • README.md
  • SQLite.CodeFirst.Test/IntegrationTests/CascadeOnUpdateTest.cs
  • SQLite.CodeFirst.Test/UnitTests/Statement/ForeignKeyStatementTest.cs
  • SQLite.CodeFirst/Internal/Builder/ForeignKeyStatementBuilder.cs
  • SQLite.CodeFirst/Internal/Statement/ForeignKeyStatement.cs
  • SQLite.CodeFirst/Internal/Utility/SqliteAssociationType.cs
  • SQLite.CodeFirst/Public/Attributes/CascadeOnUpdateAttribute.cs
  • SQLite.CodeFirst/Public/DbInitializers/SqliteInitializerBase.cs

📝 Walkthrough

Walkthrough

Adds CascadeOnUpdateAttribute that can be placed on a dependent FK property to emit ON UPDATE CASCADE in SQLite foreign key constraint DDL. The attribute is registered as a column annotation, detected by SqliteAssociationType, surfaced via a new CascadeUpdate property on ForeignKeyStatement, and wired through ForeignKeyStatementBuilder. Unit and integration tests validate the generated SQL, and the README is updated.

Changes

CascadeOnUpdate Support

Layer / File(s) Summary
CascadeOnUpdateAttribute and model registration
SQLite.CodeFirst/Public/Attributes/CascadeOnUpdateAttribute.cs, SQLite.CodeFirst/Public/DbInitializers/SqliteInitializerBase.cs, README.md
Introduces the sealed CascadeOnUpdateAttribute with a CanCascade flag and two constructors, registers it as a SQLite column annotation alongside existing attribute registrations, and documents the new "Cascade on update" feature in the README.
Association-type detection, FK statement, and builder wiring
SQLite.CodeFirst/Internal/Utility/SqliteAssociationType.cs, SQLite.CodeFirst/Internal/Statement/ForeignKeyStatement.cs, SQLite.CodeFirst/Internal/Builder/ForeignKeyStatementBuilder.cs
SqliteAssociationType scans FK ToProperties for the CascadeOnUpdateAttribute annotation to compute a CascadeUpdate boolean; ForeignKeyStatement adds a CascadeUpdate property and conditionally appends ON UPDATE CASCADE in CreateStatement(); ForeignKeyStatementBuilder forwards CascadeUpdate from the association type to the statement.
Unit and integration tests
SQLite.CodeFirst.Test/UnitTests/Statement/ForeignKeyStatementTest.cs, SQLite.CodeFirst.Test/IntegrationTests/CascadeOnUpdateTest.cs
Unit tests assert exact SQL output for CascadeUpdate-only and combined CascadeDelete+CascadeUpdate flag combinations. Integration tests create an in-memory EF model with decorated and undecorated FK properties and verify presence or absence of ON UPDATE CASCADE per relationship.

Sequence Diagram

sequenceDiagram
  participant App as Application
  participant Initializer as SqliteInitializerBase
  participant AssocType as SqliteAssociationType
  participant Builder as ForeignKeyStatementBuilder
  participant Statement as ForeignKeyStatement

  rect rgba(100, 149, 237, 0.5)
    App->>Initializer: InitializeDatabase(context)
    Initializer->>Initializer: RegisterAttributeAsColumnAnnotation[CascadeOnUpdateAttribute]
    Initializer->>AssocType: new SqliteAssociationType(storeAssociation)
    AssocType->>AssocType: scan ToProperties for CascadeOnUpdateAttribute annotation
    AssocType-->>Builder: CascadeUpdate = true
    Builder->>Statement: new ForeignKeyStatement { CascadeDelete, CascadeUpdate }
    Statement-->>Builder: CreateStatement() → "FOREIGN KEY ... ON DELETE CASCADE ON UPDATE CASCADE"
    Builder-->>Initializer: DDL SQL
    Initializer-->>App: database initialized
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 Hop, hop, the keys cascade anew,
On UPDATE they follow, true through and through!
A little attribute, sealed with care,
Placed on the FK — and voilà, it's there.
ON UPDATE CASCADE echoes in SQL space,
The rabbit has tidied the foreign key place. 🗝️

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is empty, containing only a dash character. Provide a meaningful description explaining the feature, its purpose, and how to use the new CascadeOnUpdateAttribute.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for ON UPDATE CASCADE via a new CascadeOnUpdate attribute.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fervent-solomon-9af87c

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@msallin msallin merged commit 82c1e25 into master Jun 16, 2026
4 checks passed
@msallin msallin deleted the claude/fervent-solomon-9af87c branch June 16, 2026 04:18
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.

1 participant