Skip to content

feat(datagrid): show the rows a cascading delete changes before it runs - #3703

Merged
datlechin merged 3 commits into
mainfrom
feat/3616-cascade-delete-preview
Oct 20, 2026
Merged

datlechin merged 3 commits into
mainfrom
feat/3616-cascade-delete-preview

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • Saving staged row deletes reads the foreign keys declared in the table's schema, follows ON DELETE CASCADE up to 5 keys deep, and counts the rows each key deletes, sets to NULL or default, or protects, with read-only SELECT COUNT(*) queries.
  • The delete prompt names the table and lists one line per affected table. A RESTRICT or NO ACTION key with rows behind it says the save will fail. Rows the same save deletes anyway are left out of block and rewrite counts.
  • The prompt says what it could not check: counts not read in time (5 s budget) or failed, tables past the depth limit, keys not followed (hop limit, an ON UPDATE rule on a rewritten key), other schemas, an open transaction the counts cannot see, key columns the same save edits, and "Ignore foreign key checks" on a staged table operation.
  • Foreign keys off on the connection (SQLite PRAGMA foreign_keys, MySQL foreign_key_checks): the prompt says nothing cascades instead of listing counts.
  • Show beside a line cancels the save, keeps the deletes staged and opens those rows in a new tab with a raw SQL filter.
  • Counts run on a pooled connection where the engine has one, so a cancelled count cannot abort a PostgreSQL transaction. The enforcement read uses the save's own connection.
  • An edit or tab switch while counting ends the save with a message instead of running a stale plan.
  • SQL Server: foreign key reads now report ON DELETE and ON UPDATE; before, every key read as NO ACTION. The per-table and schema-wide reads share one query, and the iOS app passes the actions through.

Test plan

  • CascadeDeletePlanTests, ReferencingKeyTests, CascadeDeleteSQLTests, CascadeDeletePreviewerTests, BulkDeleteConfirmationTests (TableProTests). BulkDeleteConfirmationTests changed on purpose: the title now names the table.
  • MSSQLSchemaQueriesTests (TableProMSSQLCoreTests): action columns, the schema-wide query, NO_ACTION/SET_NULL parsing.
  • apple/scripts/probes/check-sqlite-cascade-delete-counts.sh against SQLite 3.54.0: the generated counts equal what the DELETE removes and nulls (15/60/9), and the parent's collation and affinity apply.

Not in this PR

  • Keys declared in another schema are not read; the prompt says so. Reading them needs a PluginKit call for referencing keys across schemas.
  • Cell edits made while a save is writing are cleared when it finishes (finishSuccessfulSave in RowEditingCoordinator+SaveChanges.swift).
  • The "Ignore foreign key checks" epilogue on SQLite sets PRAGMA foreign_keys = ON even when the session had it off (fkEnableStatements), which turns cascades on for later saves.
  • MySQL checks NO ACTION and SQLite checks RESTRICT row by row, so deleting a parent and its child in one save can still fail there although the prompt leaves those rows out of the blockers.

Fixes #3616

@datlechin
datlechin enabled auto-merge (squash) October 20, 2026 16:11
@datlechin
datlechin merged commit 41e4289 into main Oct 20, 2026
13 of 15 checks passed
@datlechin
datlechin deleted the feat/3616-cascade-delete-preview branch October 21, 2026 03:53
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.

Show the rows a cascading delete will remove before it runs

1 participant