Skip to content
Browse files

Deprecate passing a string as third argument of `add_index`

This was there due historical reasons since
7dc4581 to give the user the
possibility to create unique indexes passing "UNIQUE" as the third
argument
  • Loading branch information...
1 parent 96bcef9 commit 7042fe2f8428b713894601a9bc9bdcdbcdbfb37b @rafaelfranca rafaelfranca committed
View
7 activerecord/CHANGELOG.md
@@ -1,5 +1,12 @@
## Rails 4.0.0 (unreleased) ##
+* Deprecate the possibility to pass a string as third argument of `add_index`.
+ Pass `unique: true` instead.
+
+ add_index(:users, :organization_id, unique: true)
+
+ *Rafael Mendonça França*
+
* Raise an `ArgumentError` when passing an invalid option to `add_index`.
*Rafael Mendonça França*
View
6 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -629,6 +629,12 @@ def add_index_options(table_name, column_name, options = {})
index_options = options[:where] ? " WHERE #{options[:where]}" : ""
end
else
+ message = "Passing a string as third argument of `add_index` is deprecated and will" +
+ " be removed in Rails 4.1." +
+ " Use add_index(#{table_name.inspect}, #{column_name.inspect}, unique: true) instead"
+
+ ActiveSupport::Deprecation.warn message
+
index_type = options
end
View
10 activerecord/test/cases/migration/index_test.rb
@@ -97,6 +97,16 @@ def test_valid_index_options
end
end
+ def test_deprecated_type_argument
+ message = "Passing a string as third argument of `add_index` is deprecated and will" +
+ " be removed in Rails 4.1." +
+ " Use add_index(:testings, [:foo, :bar], unique: true) instead"
+
+ assert_deprecated message do
+ connection.add_index :testings, [:foo, :bar], "UNIQUE"
+ end
+ end
+
def test_unique_index_exists
connection.add_index :testings, :foo, :unique => true

0 comments on commit 7042fe2

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