aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-02 19:51:06 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-02 20:03:26 -0200
commit7042fe2f8428b713894601a9bc9bdcdbcdbfb37b (patch)
tree5f0bc8410db0395c996d5a85e9a2416910b371c4 /activerecord
parent96bcef947bf713b7d9fc88f26dff69f568111262 (diff)
downloadrails-7042fe2f8428b713894601a9bc9bdcdbcdbfb37b.tar.gz
rails-7042fe2f8428b713894601a9bc9bdcdbcdbfb37b.tar.bz2
rails-7042fe2f8428b713894601a9bc9bdcdbcdbfb37b.zip
Deprecate passing a string as third argument of `add_index`
This was there due historical reasons since 7dc45818dc43c163700efc9896a0f3feafa31138 to give the user the possibility to create unique indexes passing "UNIQUE" as the third argument
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md7
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb6
-rw-r--r--activerecord/test/cases/migration/index_test.rb10
3 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index da149dac54..28d8b066e0 100644
--- a/activerecord/CHANGELOG.md
+++ b/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*
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index a606a5c775..2d7ec55d3e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -629,6 +629,12 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb
index bfa275fee2..0787414d8f 100644
--- a/activerecord/test/cases/migration/index_test.rb
+++ b/activerecord/test/cases/migration/index_test.rb
@@ -97,6 +97,16 @@ module ActiveRecord
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