diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-20 22:28:12 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-20 22:28:12 +0000 |
commit | b72763a96f0c936699d0f211be553f8f75accd07 (patch) | |
tree | 8951fa0f5b633df9927cc95e8234705938893dd4 /activerecord/lib/active_record/connection_adapters | |
parent | f16cd7220ff94ea2ec5b9b8a7db02af0b5365858 (diff) | |
download | rails-b72763a96f0c936699d0f211be553f8f75accd07.tar.gz rails-b72763a96f0c936699d0f211be553f8f75accd07.tar.bz2 rails-b72763a96f0c936699d0f211be553f8f75accd07.zip |
SQLite: fix rename_ and remove_column for columns with unique indexes. Closes #10576.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8453 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 586594e0ef..cd619143e6 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -304,13 +304,13 @@ module ActiveRecord yield @definition if block_given? end - copy_table_indexes(from, to) + copy_table_indexes(from, to, options[:rename] || {}) copy_table_contents(from, to, @definition.columns.map {|column| column.name}, options[:rename] || {}) end - def copy_table_indexes(from, to) #:nodoc: + def copy_table_indexes(from, to, rename = {}) #:nodoc: indexes(from).each do |index| name = index.name if to == "altered_#{from}" @@ -319,10 +319,17 @@ module ActiveRecord name = name[5..-1] end - # index name can't be the same - opts = { :name => name.gsub(/_(#{from})_/, "_#{to}_") } - opts[:unique] = true if index.unique - add_index(to, index.columns, opts) + to_column_names = columns(to).map(&:name) + columns = index.columns.map {|c| rename[c] || c }.select do |column| + to_column_names.include?(column) + end + + unless columns.empty? + # index name can't be the same + opts = { :name => name.gsub(/_(#{from})_/, "_#{to}_") } + opts[:unique] = true if index.unique + add_index(to, columns, opts) + end end end |