Skip to content

Sqlite: do not add foreign key constraints to temporary tables#736

Merged
paul-rouse merged 4 commits intoyesodweb:masterfrom
paul-rouse:sqlite-735
Nov 24, 2017
Merged

Sqlite: do not add foreign key constraints to temporary tables#736
paul-rouse merged 4 commits intoyesodweb:masterfrom
paul-rouse:sqlite-735

Conversation

@paul-rouse
Copy link
Contributor

Fixes #735

@MaxGabriel, @psibi would one of you mind checking my logic, please? The issue is that migration can involve creating a temporary table, and we were adding foreign key constraints that existed in the table being copied. Sqlite doesn't handle FK constraints from temporary tables to non-temporary ones - it probably doesn't make sense to do so - and when checking is switched on, it reports them as violated.

The fix is simply to omit the FK constraint from the temporary table!

, scientific

if !flag(postgresql) && !flag(mysql) && !flag(mongodb) && !flag(zookeeper)
cpp-options: -DWITH_SQLITE -DDEBUG
Copy link
Member

Choose a reason for hiding this comment

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

This seems a little weird—why not have a flag for SQLite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just doing for test/main.hs what was already being done for the main test modules in the library

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, it's this way so that SQLite is the default. 👍

, case ref of
Nothing -> ""
Just (table, _) -> " REFERENCES " <> escape table
Just (table, _) -> if noRef then "" else " REFERENCES " <> escape table
Copy link
Member

Choose a reason for hiding this comment

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

So the other option would be to set ref on each Column to Nothing. I kind of like that because it reduces the amount of branching. But I could also see an argument that it's confusing to modify the data of Column, which actually hasn't changed, and the Bool parameter is better because it shows that the data is being overridden. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are in the function which is being mapped over the columns, so it seemed easiest to do the work here. Does that sound reasonable?

Copy link
Member

Choose a reason for hiding this comment

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

Ok cool. PR LGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @MaxGabriel !

Copy link
Member

@psibi psibi left a comment

Choose a reason for hiding this comment

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

LGTM!

@paul-rouse
Copy link
Contributor Author

Thanks @psibi !

@paul-rouse paul-rouse merged commit 0f1f552 into yesodweb:master Nov 24, 2017
@paul-rouse paul-rouse deleted the sqlite-735 branch November 24, 2017 17:24
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.

persistent-sqlite regression between 2.6.0.1 and 2.6.2

3 participants