diff options
author | Matthew Draper <matthew@trebex.net> | 2017-04-17 02:58:52 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-17 02:58:52 +0930 |
commit | e1e3be7c02acb0facbf81a97bbfe6d1a6e9ca598 (patch) | |
tree | 5640f0f52e7f19bc349abb3127cff6ea4437b305 /activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb | |
parent | 01caad190f8f6aa1fe36f1cda764f22b6df72e22 (diff) | |
parent | 606830d27a32fab23c0964b4383807fcdfdd7eba (diff) | |
download | rails-e1e3be7c02acb0facbf81a97bbfe6d1a6e9ca598.tar.gz rails-e1e3be7c02acb0facbf81a97bbfe6d1a6e9ca598.tar.bz2 rails-e1e3be7c02acb0facbf81a97bbfe6d1a6e9ca598.zip |
Merge pull request #28773 from kamipo/support_descending_indexes
Support Descending Indexes for MySQL
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb | 35 |
1 files changed, 35 insertions, 0 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 8066a05c5e..e02491edb6 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb @@ -2,6 +2,41 @@ module ActiveRecord module ConnectionAdapters module SQLite3 module SchemaStatements # :nodoc: + # Returns an array of indexes for the given table. + def indexes(table_name, name = nil) + if name + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Passing name to #indexes is deprecated without replacement. + MSG + end + + exec_query("PRAGMA index_list(#{quote_table_name(table_name)})", "SCHEMA").map do |row| + index_sql = select_value(<<-SQL, "SCHEMA") + SELECT sql + FROM sqlite_master + WHERE name = #{quote(row['name'])} AND type = 'index' + UNION ALL + SELECT sql + FROM sqlite_temp_master + WHERE name = #{quote(row['name'])} AND type = 'index' + SQL + + /\sWHERE\s+(?<where>.+)$/i =~ index_sql + + columns = exec_query("PRAGMA index_info(#{quote(row['name'])})", "SCHEMA").map do |col| + col["name"] + end + + IndexDefinition.new( + table_name, + row["name"], + row["unique"] != 0, + columns, + where: where + ) + end + end + private def schema_creation SQLite3::SchemaCreation.new(self) |