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

Support for check constraints #92

Open
jonleighton opened this issue Mar 5, 2013 · 4 comments
Open

Support for check constraints #92

jonleighton opened this issue Mar 5, 2013 · 4 comments

Comments

@jonleighton
Copy link
Contributor

I'd love to see support for check constraints in schema_plus.

Thanks

@ronen
Copy link
Member

ronen commented Mar 10, 2013

@jonleighton seems reasonable thing to want. Do you have specific thoughts about syntax and functionality? Off the top of my head it would look like

create_table :things do |t|
    t.integer :x,                  check: "x < 100"          # column constraint
    t.integer :y,                  check: { expression: "y < 100", name: "constraint_name" }
    t.check "x + y > 100"
    t.check "x + y < 150", name: "constraint_name"
 end

where t.check the expression string would contain literal SQL. Plus it would need

 connection.checks('big_items')       #=> array of Check structs having .name and .expression
 BigItems.checks                           #=> same
 Migration.add_check table_name, expression, name: optional_constraint_name
 Migration.remove_check table_name, constraint_name

and of course the schema dumper should dump constraints using the above syntax.

This all seems straightforward to implement. Just a matter of coding it up :) It would follow the same pattern as foreign keys: define an object to store the check definition, column option handler, schema statements, etc. plus adapter-specific code for the queries. (Hmm, almost calls out for some meta-programming to support that pattern....) and of course specs to test it all.

Unfortunately I don't have the time to jump into it right now. Maybe you or somebody else out there in github-land?

@jonleighton
Copy link
Contributor Author

@ronen your proposal sounds good to me. unfortunately I probably won't be able to find time to implement it in the near future though, sorry. I will try to rabble rouse of twitter, perhaps somebody will be interested in working on it. if you'd prefer not to keep open feature requests on GH then feel free to close this, I won't be offended :)

@ronen
Copy link
Member

ronen commented Mar 10, 2013

@jonleighton ok, hopefully somebody will pick it up. i don't mind keeping this open, i'll just label it as a feature request.

@tovodeverett
Copy link
Member

I'm not volunteering to do this (at least not yet), but I'll happily put it to use if someone does implement it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants