On Feb 6, 1:35 pm, cult hero <[email protected]> wrote:
> I'm trying to get more and more into the habit of moving a lot of my
> constraints to the database instead of having them in the application.
> However, for all but the most simple constraints (unique, for
> instance) I'm trying to figure out the code for the implementation in
> my migrations.
>
> For instance, I want to create some compound unique fields (as in the
> combination of the two fields is unique just like a compound primary
> key).

A unique index will do that:

  index [:col1, :col2], :unique => true

> And, is it possible to make the constraints conditional? Such as a
> compound field but the uniqueness is ONLY checked if a third boolean
> field is set to true. As a result if the field is false the uniqueness
> of the two doesn't matter.

Some databases support partial unique indexes:

  index [:col1, :col2], :unique => true, :where => :col3

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to