Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honour DEFERRABLE on all constraints in PostgreSQL #75

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Altreus
Copy link

@Altreus Altreus commented Nov 3, 2015

The docs quoted by the PostgreSQL provider say that all constraints can be deferrable.

https://metacpan.org/pod/SQL::Translator::Producer::PostgreSQL#PostgreSQL-Create-Table-Syntax

However, if we just shove DEFERRABLE on everything, most things will break, because a deferrable primary key cannot be used in someone else's foreign key.

After some discussion in #dbix-class we decided it would suffice to change the DEFERRABLE default so that it is true for foreign keys, but false otherwise. This mimics the existing behaviour, while still allowing for the new behaviour to be specified.

I've fixed the tests to allow for this change, but I've not extended them to look for it.

@Altreus
Copy link
Author

Altreus commented Nov 3, 2015

@ilmari has mentioned that pg also has INITIALLY DEFERRED and INITIALLY IMMEDIATE

I haven't dealt with that situation because the original code didn't; I consider this PR a bugfix, and that a new feature, hence out of scope, to my mind.

Well, I didn't deal with that situation because I didn't consider it, but I still think it deserves its own feature request.

@@ -56,6 +56,7 @@ Object constructor.
match_type => 'full', # how to match
on_delete => 'cascade', # what to do on deletes
on_update => '', # what to do on updates
deferrable => 0, # whether to set DEFERRABLE, if supported by the database
Copy link
Contributor

Choose a reason for hiding this comment

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

@Altreus Ah I now understand. I thought you implemented the deferrable flag as an {extra} since it is supported by one and onky one highly non-standard engine. Hence why I was talking about sqlt_extra and was confused by how names etc applies in the other PR.

I really recommend moving this to extra like all other non-standard extension, e.g.: https://metacpan.org/pod/SQL::Translator::Producer::MySQL#Extra-attributes

Then the entire not on what is and isn't ignored in https://github.com/dbsrgits/dbix-class/pull/88/files#diff-14a995427a39511927479ae4ffbbb9c7R768 becomes moot.

@ilmari thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

deferrable constraints are part of the SQL standard, so I'm with @ilmari's original implementation here (sorry to revive a 6-year old thread, i'm just reviewing this to merge b/c I need it for $work)

@ribasushi
Copy link
Contributor

@Altreus it is still on my radar, because it integrates with a part of DBIC I have postponed looking at it until I get the corresponding part in DBIC thought through.

At this point there is nothing you need to do about it, ignore the coverage thing.

Sorry for the delays, I am working as fast as I can.

@Altreus
Copy link
Author

Altreus commented Mar 3, 2016

Thanks for the update. Let me know if I can help with further changes!

@codecov
Copy link

codecov bot commented Jan 18, 2018

Codecov Report

Merging #75 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #75      +/-   ##
==========================================
+ Coverage    21.5%   21.53%   +0.03%     
==========================================
  Files          71       71              
  Lines       19913    19917       +4     
  Branches     5728     5730       +2     
==========================================
+ Hits         4282     4289       +7     
  Misses      14922    14922              
+ Partials      709      706       -3
Impacted Files Coverage Δ
lib/SQL/Translator/Schema/Constraint.pm 82.05% <ø> (ø) ⬆️
lib/SQL/Translator/Producer/PostgreSQL.pm 82.47% <100%> (+0.36%) ⬆️
lib/Test/SQL/Translator.pm 78.86% <100%> (+1.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c44281d...da2e927. Read the comment docs.

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.

3 participants