From 1f4dc25250d828dd7f4c2c1c8e1d23c24c3e8d0b Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 24 Sep 2005 00:33:47 +0000 Subject: Make the sqlite adapter preserve not-null constraints and index names when altering tables git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2318 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../active_record/connection_adapters/sqlite_adapter.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 7d2d8986a1..e426149e02 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -261,7 +261,8 @@ module ActiveRecord options[:rename][column.name] if options[:rename] @definition.column(column_name || column.name, column.type, - :limit => column.limit, :default => column.default) + :limit => column.limit, :default => column.default, + :null => column.null) end @definition.primary_key(primary_key(from)) yield @definition if block_given? @@ -275,8 +276,16 @@ module ActiveRecord def copy_table_indexes(from, to) #:nodoc: indexes(from).each do |index| - type = index[:unique] ? 'UNIQUE' : '' - add_index(to, index[:columns], type) + name = index.name + if to == "altered_#{from}" + name = "temp_#{name}" + elsif from == "altered_#{to}" + name = name[5..-1] + end + + opts = { :name => name } + opts[:unique] = true if index.unique + add_index(to, index.columns, opts) end end -- cgit v1.2.3