Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Add handling of referential actions for foreign key constraints. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fvbock
Copy link

@fvbock fvbock commented Sep 13, 2012

CASCADE, SET NULL, and NO ACTION are translated as is.
No action defined is - per MySQL documentation actually RESTRICT and thus translated as such.
(SET DEFAULT is not accepted by InnoDB)

CASCADE, SET NULL, and NO ACTION are translated as is.
No action defined is - per MySQL documentation actually RESTRICT and thus translated as such.
(SET DEFAULT is not accepted by InnoDB)
@fvbock
Copy link
Author

fvbock commented Sep 13, 2012

just saw that the travis build failed... had a brief look but could not figure out right away whether it's related to my patch or something else... let me know if you'd need me to patch some test code too.

@kworr
Copy link
Collaborator

kworr commented Sep 14, 2012

Travis history shows no single success so this is not you.

@kworr
Copy link
Collaborator

kworr commented Sep 19, 2012

0kaaay, I had taken some time to study the code and MySQL/PostgreSQL view on standarts.

  1. There are a lot of 'if's in your patch. The code can be wastly simplified, like this:

    for action in ['UPDATE', 'DELETE']:
      match = re.compile(' ON %s (CASCADE|SET NULL|RESTRICT|NO ACTION|SET DEFAULT)' % action, re.I)
      if match:
        index[action] = 'ON %s %s' % (action, match.group(1))
    

    This is kind of rough example but it saves a lot of ifs and populates index with a final string to output.

    And adding them to the full line regexp would be much better than processing same line with regexp three times. However there is a question whether all MySQL versions generate this line the same way...

  2. Why RESTRICT? NO ACTION is fine default by itself and I see no reasons for changing this. It's not about my preference as I prefer RESTRICT to NO ACTION, but about how MySQL treats triggers and would it enable them alter the data before actual foreign key check is fired. If yes then NO ACTION is closer to MySQL behavior.

@kworr kworr added the feedback label Aug 28, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants