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

options: "deferrable" missing in schema.rb #148

Closed
mkllnk opened this issue Jul 4, 2014 · 5 comments
Closed

options: "deferrable" missing in schema.rb #148

mkllnk opened this issue Jul 4, 2014 · 5 comments

Comments

@mkllnk
Copy link

mkllnk commented Jul 4, 2014

Hello,

I use add_foreign_key to add deferrable constraints to a PostgreSQL database.

add_foreign_key "spree_orders", "carts", name: "spree_orders_cart_id_fk", options: "deferrable"

That works fine in the migration and all commands are added to schema.rb --- except the last part , options: "deferrable". There is just:

add_foreign_key "spree_orders", "carts", name: "spree_orders_cart_id_fk"

Am I doing something wrong? Is it out of scope or a bug?

@subakva
Copy link

subakva commented Aug 15, 2014

It looks as if this has been a problem for a while: #105 (comment)

For what it's worth, you can work around this by dumping your schema in SQL format.

In application.rb:

  config.active_record.schema_format = :sql

@jenseng
Copy link
Contributor

jenseng commented Sep 25, 2014

@matthuhiggins although you don't plan to support database-specific features (understandable, and i agree), what's your take on inferring/preserving the :options in schema dumper? if you're ok with that, i'd be happy to throw together a PR for it.

seems like that would solve this particular issue, and greatly reduce db-specific feature requests in the future :)

@matthuhiggins
Copy link
Owner

Hmm, I could go for that. Do you think you could parse out the options in a sufficiently generic way?

@jenseng
Copy link
Contributor

jenseng commented Sep 25, 2014

yeah it looks pretty trivial...

for mysql it's a noop because it doesn't support any options after the ON <event> <action>

for postgresql, we can just take whatever appears after the ON <event> <action> ... that would be the stuff like DEFERRABLE / NOT VALID that people are expecting

i don't think we need to do anything beyond that, because things like MATCH matchtype and actions like SET DEFAULT:

  1. appear in different places in the statement,
  2. are pretty db-specific, and
  3. can't even be specified by an add_foreign_key call so it doesn't make sense to preserve them

@matthuhiggins
Copy link
Owner

Sounds like a plan

matthuhiggins added a commit that referenced this issue Sep 29, 2014
preserve db-specific options in schema.rb, fixes #148
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

No branches or pull requests

4 participants