aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
index 3ab9dee370..58e5138e02 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
@@ -19,14 +19,17 @@ module ActiveRecord
/\sWHERE\s+(?<where>.+)$/i =~ index_sql
- 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 = exec_query("PRAGMA index_info(#{quote(row['name'])})", "SCHEMA").map do |col|
+ col["name"]
+ end
- columns << col["name"]
- orders[col["name"]] = :desc if col["desc"] == 1
+ # Add info on sort order for columns (only desc order is explicitly specified, asc is
+ # the default)
+ orders = {}
+ if index_sql # index_sql can be null in case of primary key indexes
+ index_sql.scan(/"(\w+)" DESC/).flatten.each { |order_column|
+ orders[order_column] = :desc
+ }
end
IndexDefinition.new(
@@ -34,8 +37,8 @@ module ActiveRecord
row["name"],
row["unique"] != 0,
columns,
- orders: orders,
- where: where
+ where: where,
+ orders: orders
)
end
end