Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for renaming primary key columns on MySQL

  • Loading branch information...
commit 44b3e6be7dfcf2626db7738c104b8509e5b31ff7 1 parent e2e8df2
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Add support for renaming primary key columns on MySQL (jeremyevans)
+
* Add connection_validator extension for automatically checking connections and transparently handling disconnects (jeremyevans)
* Add Database#valid_connection? for checking whether a given connection is valid (jeremyevans)
View
1  lib/sequel/adapters/shared/mysql.rb
@@ -195,6 +195,7 @@ def alter_table_op_sql(table, op)
opts[:null] = o == :set_column_null ? op[:null] : opts[:allow_null]
opts[:default] = o == :set_column_default ? op[:default] : opts[:ruby_default]
opts.delete(:default) if opts[:default] == nil
+ opts.delete(:primary_key) if op[:op] == :rename_column
"CHANGE COLUMN #{quote_identifier(op[:name])} #{column_definition_sql(op.merge(opts))}"
when :drop_constraint
type = case op[:type]
View
9 spec/integration/schema_test.rb
@@ -430,6 +430,15 @@
@db[:items2].select_order_map([:id, :b]).should == [[1, 10], [2, 20]]
end
+ cspecify "should rename primary_key columns correctly", :db2 do
+ @db.create_table!(:items){Integer :id, :primary_key=>true}
+ @ds.insert(:id=>10)
+ @db.alter_table(:items){rename_column :id, :id2}
+ @db.schema(:items, :reload=>true).map{|x| x.first}.should == [:id2]
+ @ds.columns!.should == [:id2]
+ @ds.all.should == [{:id2=>10}]
+ end
+
cspecify "should set column NULL/NOT NULL correctly", [:jdbc, :db2], [:db2] do
@db.create_table!(:items, :engine=>:InnoDB){Integer :id}
@ds.insert(:id=>10)

2 comments on commit 44b3e6b

@kartikrustagi

Don't we need to do the same for others as well. Like for :set_column_type as well we will have to remove the :primary_key option.

@jeremyevans

I think you are right. I'll make the change soon.

Please sign in to comment.
Something went wrong with that request. Please try again.