mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36740 from stanhu/sh-fix-index-exists-postgresql-partial-index
Fix index_exists? for PostgreSQL expression indexes
This commit is contained in:
commit
4ee88df6a0
2 changed files with 5 additions and 3 deletions
|
@ -100,7 +100,7 @@ module ActiveRecord
|
|||
def index_exists?(table_name, column_name, options = {})
|
||||
column_names = Array(column_name).map(&:to_s)
|
||||
checks = []
|
||||
checks << lambda { |i| i.columns == column_names }
|
||||
checks << lambda { |i| Array(i.columns) == column_names }
|
||||
checks << lambda { |i| i.unique } if options[:unique]
|
||||
checks << lambda { |i| i.name == options[:name].to_s } if options[:name]
|
||||
|
||||
|
|
|
@ -253,9 +253,11 @@ module ActiveRecord
|
|||
|
||||
def test_expression_index
|
||||
with_example_table do
|
||||
@connection.add_index "ex", "mod(id, 10), abs(number)", name: "expression"
|
||||
expr = "mod(id, 10), abs(number)"
|
||||
@connection.add_index "ex", expr, name: "expression"
|
||||
index = @connection.indexes("ex").find { |idx| idx.name == "expression" }
|
||||
assert_equal "mod(id, 10), abs(number)", index.columns
|
||||
assert_equal expr, index.columns
|
||||
assert_equal true, @connection.index_exists?("ex", expr, name: "expression")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue