yesodweb / yesodweb/persistent

Consider changing On{Update,Delete} FK default behaviour from RESTRICT to NO ACTION

Open
#1,416 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

At the moment, the OnUpdate and OnDelete behaviour for a foreign key declared in a persistentmodels file defaults to RESTRICT if not specified. However, I think NO ACTION might be a better default: it matches all supported SQL databases' defaults, and for databases that support it, it offers a little more flexibility without losing data integrity guarantees (because the FK is still checked, just not until the end of the transaction, as opposed to immediately).

I didn't see much previous discussion of this in the change that initially implemented the ability to specify OnUpdate/OnDelete in persistentmodels files (#1145) but please do let me know if I've missed anything.

This change would of course have to wait for a breaking release if we were going to do it, and it would generate a number of new migrations for existing databases that were previously considered to have their DB schemas up to date, but I think we usually consider this acceptable in breaking releases?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the persistentmodels handling for OnUpdate and OnDelete defaults and the schema or migration generation path. Compare the resulting foreign-key behavior across MySQL, PostgreSQL, and SQLite, then verify that changing the default to NO ACTION produces the expected migrations for existing databases without weakening integrity guarantees.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.