diff options
author | Paul Kuruvilla <rohitpaulk@gmail.com> | 2017-10-24 19:03:37 +0530 |
---|---|---|
committer | Paul Kuruvilla <rohitpaulk@gmail.com> | 2017-10-24 22:39:44 +0530 |
commit | 82ae8369925e152d507486f7520558ac09f090e8 (patch) | |
tree | 08eccd87dc45e82760eac0d7ee2c0d82efc9265f /activerecord/lib/active_record | |
parent | 4aac0bf66c1d18c23f2096d9a343dbf9a95cbf23 (diff) | |
download | rails-82ae8369925e152d507486f7520558ac09f090e8.tar.gz rails-82ae8369925e152d507486f7520558ac09f090e8.tar.bz2 rails-82ae8369925e152d507486f7520558ac09f090e8.zip |
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.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb | 11 |
1 files changed, 9 insertions, 2 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 f0d702136d..3ab9dee370 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb @@ -19,8 +19,14 @@ module ActiveRecord /\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 @@ module ActiveRecord row["name"], row["unique"] != 0, columns, + orders: orders, where: where ) end |