1
0
Fork 0
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:
Rafael França 2019-07-25 10:19:04 -04:00 committed by GitHub
commit 4ee88df6a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -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]

View file

@ -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