Permalink
Browse files

Support options when altering a column's type

  • Loading branch information...
1 parent 4bbbedc commit fc6e8e116312d40c00461dfea78dda945160ddd9 @jeremyevans committed Dec 1, 2008
Showing with 16 additions and 3 deletions.
  1. +2 −0 CHANGELOG
  2. +2 −2 lib/sequel_core/schema/generator.rb
  3. +1 −1 lib/sequel_core/schema/sql.rb
  4. +11 −0 spec/sequel_core/schema_spec.rb
View
@@ -1,5 +1,7 @@
=== HEAD
+* Support options when altering a column's type (for changing enums, varchar size, etc.) (jeremyevans)
+
* Support AliasedExpressions in tables when using implicitly qualified arguments in joins (jeremyevans)
* Support Dataset#except on Oracle (jeremyevans)
@@ -277,8 +277,8 @@ def set_column_default(name, default)
end
# Modify a column's type in the DDL for the table.
- def set_column_type(name, type)
- @operations << {:op => :set_column_type, :name => name, :type => type}
+ def set_column_type(name, type, opts={})
+ @operations << {:op => :set_column_type, :name => name, :type => type}.merge(opts)
end
# Modify a column's NOT NULL constraint.
@@ -29,7 +29,7 @@ def alter_table_sql(table, op)
when :rename_column
"RENAME COLUMN #{quoted_name} TO #{quote_identifier(op[:new_name])}"
when :set_column_type
- "ALTER COLUMN #{quoted_name} TYPE #{op[:type]}"
+ "ALTER COLUMN #{quoted_name} TYPE #{type_literal(op)}"
when :set_column_default
"ALTER COLUMN #{quoted_name} SET DEFAULT #{literal(op[:default])}"
when :set_column_null
@@ -628,6 +628,17 @@
end
@db.sqls.should == ["ALTER TABLE cats ALTER COLUMN score TYPE real"]
end
+
+ specify "should support set_column_type with options" do
+ @db.alter_table(:cats) do
+ set_column_type :score, :integer, :unsigned=>true
+ set_column_type :score, :varchar, :size=>30
+ set_column_type :score, :enum, :elements=>['a', 'b']
+ end
+ @db.sqls.should == ["ALTER TABLE cats ALTER COLUMN score TYPE integer UNSIGNED",
+ "ALTER TABLE cats ALTER COLUMN score TYPE varchar(30)",
+ "ALTER TABLE cats ALTER COLUMN score TYPE enum('a', 'b')"]
+ end
end
context "Schema Parser" do

0 comments on commit fc6e8e1

Please sign in to comment.