Ok I believe the attached diff will add contraints to alter_table, but I have not been able to build it to test.
http://groups.google.com/group/sequel-talk/web/constraint_patch.diff Index: lib/sequel_core/schema/schema_sql.rb =================================================================== --- lib/sequel_core/schema/schema_sql.rb (revision 929) +++ lib/sequel_core/schema/schema_sql.rb (working copy) @@ -143,6 +143,10 @@ index_definition_sql(table, op) when :drop_index "DROP INDEX #{default_index_name(table, op[:columns])}" + when :add_constraint + "ALTER TABLE #{table} ADD #{constraint_definition_sql(op)}" + when :drop_constraint + "ALTER TABLE #{table} DROP CONSTRAINT #{literal(op[:name])}" else raise Error, "Unsupported ALTER TABLE operation" end Index: lib/sequel_core/schema/schema_generator.rb =================================================================== --- lib/sequel_core/schema/schema_generator.rb (revision 929) +++ lib/sequel_core/schema/schema_generator.rb (working copy) @@ -147,7 +147,24 @@ :columns => columns \ } end + + def add_constraint(name, *args, &block) + @operations << { \ + :op => :add_constraint, \ + :name => name, \ + :type => :check, \ + :check => block || args \ + } end + + def drop_constraint(name) + @operations << { \ + :op => :drop_constraint, \ + :name => name \ + } end + end + end +end On Feb 23, 7:08 pm, Jim Morris <[EMAIL PROTECTED]> wrote: > Ok, but what about the alter_table for constraints? > > I'll take a look and see if I can submit a patch to add this to > alter_table, it seems adding (and removing) constraints in an > alter_table would be pretty handy. > > I could use it right now as I am doing migrations and having to add a > check manually with execute. > > On Feb 23, 12:49 pm, Aman Gupta <[EMAIL PROTECTED]> wrote: > > > On Feb 22, 12:25 pm, Jim Morris <[EMAIL PROTECTED]> wrote: > > > > This is excellent! > > > > However is there a way to have this work in an alter_table block? or > > > is there another way to add constraints to an existing table? > > > > Also is there any formal documentation for check? or a wiki page? > > > Nothing yet, there should be some rdocs.. If someone more familiar > > with the subject wants to write up a wiki page on the topic, I'll get > > it up on the site. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
