Skip to content

Conversation

@kderme
Copy link
Contributor

@kderme kderme commented Mar 19, 2020

I tried to fix #910. It works only for table constaints and not for field constraints. Also it only works and is tested on SQLite, but I think making postgres work is just a matter of copy-pase. No existing migrations break.

Some of the options, like 'OnDeleteSetNull' are not useful at the moment, because of the limitation of persistent to only make possible to refer to primary keys of other tables (which can't be NULL anyway).

Not to be confused with what mkDeleteCascade does. The approach here is to let the db do all the cascading changes, instead of manually updating other tables.

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

Comment on lines +914 to +915
errorPrefix :: String
errorPrefix = "invalid foreign key constraint on table[" ++ show tableName ++ "] "
Copy link
Contributor Author

@kderme kderme Mar 19, 2020

Choose a reason for hiding this comment

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

Suggested change
errorPrefix :: String
errorPrefix = "invalid foreign key constraint on table[" ++ show tableName ++ "] "
mkError :: String -> a
mkError str = error $ conat ["invalid foreign key constraint on table[", show tableName, "] ", str]

Maybe this is cleaner to use

Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

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

I dig it. I'm going to merge this into a branch and provide Postgresql/MySQL support. Thanks!

@parsonsmatt parsonsmatt changed the base branch from master to matt/cascade-merge March 30, 2020 18:42
@parsonsmatt parsonsmatt merged commit 2f0a2ea into yesodweb:matt/cascade-merge Mar 30, 2020
@parsonsmatt parsonsmatt mentioned this pull request Mar 30, 2020
5 tasks
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.

Foreign Key Cascade

2 participants