提交 82ae8369 编写于 作者: P Paul Kuruvilla

Save index order :desc to schema.rb (sqlite). Fixes #30902

Although the sqlite adapter supports index sort orders, they
weren't being written to db/schema.rb.
上级 4aac0bf6
* Fixed a bug where column orders for an index weren't written to
db/schema.rb when using the sqlite adapter.
Fixes #30902.
*Paul Kuruvilla*
* Remove deprecated method `#sanitize_conditions`.
*Rafael Mendonça França*
......
......@@ -19,8 +19,14 @@ def indexes(table_name)
/\sWHERE\s+(?<where>.+)$/i =~ index_sql
columns = exec_query("PRAGMA index_info(#{quote(row['name'])})", "SCHEMA").map do |col|
col["name"]
columns = []
orders = {}
exec_query("PRAGMA index_xinfo(#{quote(row['name'])})", "SCHEMA").each do |col|
# xinfo also lists non-key columns, let's filter those out
next if col["key"] == 0
columns << col["name"]
orders[col["name"]] = :desc if col["desc"] == 1
end
IndexDefinition.new(
......@@ -28,6 +34,7 @@ def indexes(table_name)
row["name"],
row["unique"] != 0,
columns,
orders: orders,
where: where
)
end
......
......@@ -186,7 +186,7 @@ def test_schema_dumps_index_columns_in_right_order
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", length: { type: 10 }', index_definition
end
else
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index"', index_definition
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", order: { rating: :desc }', index_definition
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册