GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of jeremyevans/sequel
Description: Sequel: The Database Toolkit for Ruby
Homepage: http://sequel.rubyforge.org
Clone URL: git://github.com/divoxx/sequel.git
Add set_column_accept_null method to AlterTableGenerator
divoxx (author)
Sun Sep 14 11:03:56 -0700 2008
commit  9ed3dd3e0a196cda90b2b222f6abc416bf382579
tree    58248f1db521fb9c2972bf2c60a55a0837e390e3
parent  bedb708b1f56c553b38f8e3f0ba901f007863f82
...
260
261
262
 
 
 
 
 
263
264
265
...
260
261
262
263
264
265
266
267
268
269
270
0
@@ -260,6 +260,11 @@ module Sequel
0
       def set_column_type(name, type)
0
         @operations << {:op => :set_column_type, :name => name, :type => type}
0
       end
0
+
0
+ # Modify a column's NOT NULL constraint.
0
+ def set_column_accept_null(name, accept_null)
0
+ @operations << {:op => :set_column_null, :name => name, :null => accept_null}
0
+ end
0
 
0
       private
0
 
...
33
34
35
 
 
36
37
38
...
33
34
35
36
37
38
39
40
0
@@ -33,6 +33,8 @@ module Sequel
0
           "ALTER COLUMN #{quoted_name} TYPE #{op[:type]}"
0
         when :set_column_default
0
           "ALTER COLUMN #{quoted_name} SET DEFAULT #{literal(op[:default])}"
0
+ when :set_column_null
0
+ "ALTER COLUMN #{quoted_name} #{op[:null] ? 'DROP' : 'SET'} NOT NULL"
0
         when :add_index
0
           return index_definition_sql(table, op)
0
         when :drop_index
...
459
460
461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
463
464
...
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
0
@@ -459,6 +459,20 @@ context "DB#alter_table" do
0
   setup do
0
     @db = SchemaDummyDatabase.new
0
   end
0
+
0
+ specify "should allow adding not null constraint" do
0
+ @db.alter_table(:cats) do
0
+ set_column_accept_null :score, false
0
+ end
0
+ @db.sqls.should == ["ALTER TABLE cats ALTER COLUMN score SET NOT NULL"]
0
+ end
0
+
0
+ specify "should allow droping not null constraint" do
0
+ @db.alter_table(:cats) do
0
+ set_column_accept_null :score, true
0
+ end
0
+ @db.sqls.should == ["ALTER TABLE cats ALTER COLUMN score DROP NOT NULL"]
0
+ end
0
 
0
   specify "should support add_column" do
0
     @db.alter_table(:cats) do

Comments

    No one has commented yet.