提交 547ed456 编写于 作者: C Cody Cutrer

sqlite >= 3.8.0 supports partial indexes

上级 8a60f479
* Enable partial indexes for sqlite >= 3.8.0
See http://www.sqlite.org/partialindex.html
*Cody Cutrer*
* Don't try to get the subclass if the inheritance column doesn't exist
The `subclass_from_attrs` method is called even if the column specified by
......
......@@ -155,6 +155,10 @@ def supports_savepoints?
true
end
def supports_partial_index?
sqlite_version >= '3.8.0'
end
# Returns true, since this connection adapter supports prepared statement
# caching.
def supports_statement_cache?
......@@ -397,13 +401,25 @@ def columns(table_name) #:nodoc:
# Returns an array of indexes for the given table.
def indexes(table_name, name = nil) #:nodoc:
exec_query("PRAGMA index_list(#{quote_table_name(table_name)})", 'SCHEMA').map do |row|
sql = <<-SQL
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
index_sql = exec_query(sql).first['sql']
match = /\sWHERE\s+(.+)$/i.match(index_sql)
where = match[1] if match
IndexDefinition.new(
table_name,
row['name'],
row['unique'] != 0,
exec_query("PRAGMA index_info('#{row['name']}')", "SCHEMA").map { |col|
col['name']
})
}, nil, nil, where)
end
end
......
......@@ -190,6 +190,8 @@ def test_schema_dumps_partial_indices
assert_equal 'add_index "companies", ["firm_id", "type"], name: "company_partial_index", where: "(rating > 10)", using: :btree', index_definition
elsif current_adapter?(:MysqlAdapter) || current_adapter?(:Mysql2Adapter)
assert_equal 'add_index "companies", ["firm_id", "type"], name: "company_partial_index", using: :btree', index_definition
elsif current_adapter?(:SQLite3Adapter) && ActiveRecord::Base.connection.supports_partial_index?
assert_equal 'add_index "companies", ["firm_id", "type"], name: "company_partial_index", where: "rating > 10"', index_definition
else
assert_equal 'add_index "companies", ["firm_id", "type"], name: "company_partial_index"', index_definition
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册