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

preserve db-specific options in schema.rb, fixes #148 #154

Merged
merged 1 commit into from
Sep 29, 2014
Merged

preserve db-specific options in schema.rb, fixes #148 #154

merged 1 commit into from
Sep 29, 2014

Conversation

jenseng
Copy link
Contributor

@jenseng jenseng commented Sep 28, 2014

basically any valid db-specific thing that you can already specify via
options: "..." will be preserved on the way back out.

for mysql that's:

  • ON UPDATE <action>

for postgres that's:

  • ON UPDATE <action>
  • ON DELETE SET DEFAULT (doesn't map to a :dependent value)
  • DEFERRABLE (NOT DEFERRABLE is the default)
  • INITIALLY DEFERRED (INITIALLY IMMEDIATE is the default)
  • NOT VALID

postgres' MATCH <type> is not supported, but that's already problematic
for :options since it is incompatible with :dependent (due to where it
appears in the statement), so ¯_(ツ)_/¯

@jenseng
Copy link
Contributor Author

jenseng commented Sep 28, 2014

so i tested this manually in mysql and postgres, and it works great, e.g.

add_foreign_key "enrollments", "users", options: <<-SQL
    ON DELETE SET DEFAULT
    ON UPDATE RESTRICT
    DEFERRABLE INITIALLY DEFERRED
    NOT VALID
  SQL

though i'm wondering what you think about adding some robust end-to-end adapter tests? e.g. in hairtrigger's schema dumper specs, i have it create a db, add tables and triggers, dump them, and then make sure the triggers are dumped correctly ... gives a bit more confidence when changing things

@jenseng
Copy link
Contributor Author

jenseng commented Sep 28, 2014

swapped order of ON UPDATE <-> ON DELETE ... works fine either way, but postgres docs indicate ON DELETE should come first

@jenseng
Copy link
Contributor Author

jenseng commented Sep 29, 2014

hmm though one gotcha is old versions of postgres ... should probably key the convalidated part of the select off of postgres_version >= 90100. all the other stuff is fine all the way back to 7.1 (and rails 3.1+ doesn't support any postgres version older than 8.2)

basically any valid db-specific thing that you can already specify via
`options: "..."` will be preserved on the way back out.

for mysql that's:
* `ON UPDATE <action>`

for postgres that's:
* `ON UPDATE <action>`
* `ON DELETE SET DEFAULT` (doesn't map to a `:dependent` value)
* `DEFERRABLE` (`NOT DEFERRABLE` is the default)
* `INITIALLY DEFERRED` (`INITIALLY IMMEDIATE` is the default)
* `NOT VALID`

postgres' `MATCH <type>` is not supported, but that's already problematic
for `:options` since it is incompatible with `:dependent` (due to where it
appears in the statement), so ¯\_(ツ)_/¯
@matthuhiggins
Copy link
Owner

I'm not concerned with postgres before 9.0.

matthuhiggins added a commit that referenced this pull request Sep 29, 2014
preserve db-specific options in schema.rb, fixes #148
@matthuhiggins matthuhiggins merged commit 579dccb into matthuhiggins:master Sep 29, 2014
@matthuhiggins
Copy link
Owner

Very cool, thanks a lot @jenseng.

End to end adapter tests would be well received. Maybe some kind of test/dummy app would be necessary.

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.

2 participants