mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Deprecate passing a string as third argument of add_index
This was there due historical reasons since
7dc45818dc
to give the user the
possibility to create unique indexes passing "UNIQUE" as the third
argument
This commit is contained in:
parent
96bcef947b
commit
7042fe2f84
3 changed files with 23 additions and 0 deletions
|
@ -1,5 +1,12 @@
|
||||||
## Rails 4.0.0 (unreleased) ##
|
## 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`.
|
* Raise an `ArgumentError` when passing an invalid option to `add_index`.
|
||||||
|
|
||||||
*Rafael Mendonça França*
|
*Rafael Mendonça França*
|
||||||
|
|
|
@ -629,6 +629,12 @@ module ActiveRecord
|
||||||
index_options = options[:where] ? " WHERE #{options[:where]}" : ""
|
index_options = options[:where] ? " WHERE #{options[:where]}" : ""
|
||||||
end
|
end
|
||||||
else
|
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
|
index_type = options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,16 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
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
|
def test_unique_index_exists
|
||||||
connection.add_index :testings, :foo, :unique => true
|
connection.add_index :testings, :foo, :unique => true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue