aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration
diff options
context:
space:
mode:
authorGrey Baker <greysteil@gmail.com>2015-04-03 09:55:53 +0100
committerGrey Baker <greysteil@gmail.com>2015-12-15 21:06:07 +0000
commit8ceb883b0630e0d010fbef0c621cc9690b0bcad6 (patch)
treeb2480a8bc75739dfb17e67313c54fe252424ab53 /activerecord/lib/active_record/migration
parent9771f5e178ebc1b8c5a61f813373ca3b7bd983c8 (diff)
downloadrails-8ceb883b0630e0d010fbef0c621cc9690b0bcad6.tar.gz
rails-8ceb883b0630e0d010fbef0c621cc9690b0bcad6.tar.bz2
rails-8ceb883b0630e0d010fbef0c621cc9690b0bcad6.zip
Support removing custom-names indexes when only specifying column names
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r--activerecord/lib/active_record/migration/compatibility.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb
index bc5b97a711..831bfa2df3 100644
--- a/activerecord/lib/active_record/migration/compatibility.rb
+++ b/activerecord/lib/active_record/migration/compatibility.rb
@@ -39,6 +39,31 @@ module ActiveRecord
end
super
end
+
+ def remove_index(table_name, options = {})
+ index_name = index_name_for_remove(table_name, options)
+ execute "DROP INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)}"
+ end
+
+ private
+
+ def index_name_for_remove(table_name, options = {})
+ index_name = index_name(table_name, options)
+
+ unless index_name_exists?(table_name, index_name, true)
+ if options.is_a?(Hash) && options.has_key?(:name)
+ options_without_column = options.dup
+ options_without_column.delete :column
+ index_name_without_column = index_name(table_name, options_without_column)
+
+ return index_name_without_column if index_name_exists?(table_name, index_name_without_column, false)
+ end
+
+ raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
+ end
+
+ index_name
+ end
end
class V4_2 < V5_0