提交 a6e0eeb8 编写于 作者: T Thomas Bianchini

Fixing an issue when parsing an opclass by allowing indexed column

in indexdef to be wrapped up by double quotes

    Fixes #34493.

    *Thomas Bianchini*
上级 536a190a
......@@ -124,7 +124,7 @@ def indexes(table_name) # :nodoc:
# add info on sort order (only desc order is explicitly specified, asc is the default)
# and non-default opclasses
expressions.scan(/(?<column>\w+)\s?(?<opclass>\w+_ops)?\s?(?<desc>DESC)?\s?(?<nulls>NULLS (?:FIRST|LAST))?/).each do |column, opclass, desc, nulls|
expressions.scan(/(?<column>\w+)"?\s?(?<opclass>\w+_ops)?\s?(?<desc>DESC)?\s?(?<nulls>NULLS (?:FIRST|LAST))?/).each do |column, opclass, desc, nulls|
opclasses[column] = opclass.to_sym if opclass
if nulls
orders[column] = [desc, nulls].compact.join(" ")
......
......@@ -507,6 +507,7 @@ class SchemaIndexOpclassTest < ActiveRecord::PostgreSQLTestCase
@connection = ActiveRecord::Base.connection
@connection.create_table "trains" do |t|
t.string :name
t.string :position
t.text :description
end
end
......@@ -530,6 +531,17 @@ def test_non_default_opclass_is_dumped
assert_match(/opclass: \{ description: :text_pattern_ops \}/, output)
end
def test_opclass_class_parsing_on_non_reserved_and_cannot_be_function_or_type_keyword
@connection.enable_extension("pg_trgm")
@connection.execute "CREATE INDEX trains_position ON trains USING gin(position gin_trgm_ops)"
@connection.execute "CREATE INDEX trains_name_and_position ON trains USING btree(name, position text_pattern_ops)"
output = dump_table_schema "trains"
assert_match(/opclass: :gin_trgm_ops/, output)
assert_match(/opclass: \{ position: :text_pattern_ops \}/, output)
end
end
class SchemaIndexNullsOrderTest < ActiveRecord::PostgreSQLTestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册