mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Omit redundant using: :btree
for schema dumping
This commit is contained in:
parent
fd6d286eda
commit
6d37cd918d
5 changed files with 17 additions and 17 deletions
|
@ -1,3 +1,7 @@
|
|||
* Omit redundant `using: :btree` for schema dumping.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
||||
* Deprecate passing `default` to `index_name_exists?`.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
|
|
@ -188,7 +188,7 @@ HEADER
|
|||
index_parts << "length: { #{format_options(index.lengths)} }" if index.lengths.present?
|
||||
index_parts << "order: { #{format_options(index.orders)} }" if index.orders.present?
|
||||
index_parts << "where: #{index.where.inspect}" if index.where
|
||||
index_parts << "using: #{index.using.inspect}" if index.using
|
||||
index_parts << "using: #{index.using.inspect}" if index.using && index.using != :btree
|
||||
index_parts << "type: #{index.type.inspect}" if index.type
|
||||
index_parts << "comment: #{index.comment.inspect}" if index.comment
|
||||
index_parts
|
||||
|
|
|
@ -113,7 +113,7 @@ if ActiveRecord::Base.connection.supports_comments?
|
|||
assert_match %r[t\.string\s+"content",\s+comment: "Whoa, content describes itself!"], output
|
||||
assert_match %r[t\.integer\s+"rating",\s+comment: "I am running out of imagination"], output
|
||||
assert_match %r[t\.index\s+.+\s+comment: "\\\"Very important\\\" index that powers all the performance.\\nAnd it's fun!"], output
|
||||
assert_match %r[t\.index\s+.+\s+name: "idx_obvious",.+\s+comment: "We need to see obvious comments"], output
|
||||
assert_match %r[t\.index\s+.+\s+name: "idx_obvious",\s+comment: "We need to see obvious comments"], output
|
||||
end
|
||||
|
||||
def test_schema_dump_omits_blank_comments
|
||||
|
|
|
@ -178,24 +178,20 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_schema_dumps_index_columns_in_right_order
|
||||
index_definition = standard_dump.split(/\n/).grep(/t\.index.*company_index/).first.strip
|
||||
index_definition = dump_table_schema("companies").split(/\n/).grep(/t\.index.*company_index/).first.strip
|
||||
if current_adapter?(:PostgreSQLAdapter)
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", order: { rating: :desc }, using: :btree', index_definition
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", order: { rating: :desc }', index_definition
|
||||
elsif current_adapter?(:Mysql2Adapter)
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", length: { type: 10 }, using: :btree', index_definition
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", length: { type: 10 }', index_definition
|
||||
else
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index"', index_definition
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dumps_partial_indices
|
||||
index_definition = standard_dump.split(/\n/).grep(/t\.index.*company_partial_index/).first.strip
|
||||
if current_adapter?(:PostgreSQLAdapter)
|
||||
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index", where: "(rating > 10)", using: :btree', index_definition
|
||||
elsif current_adapter?(:Mysql2Adapter)
|
||||
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index", using: :btree', index_definition
|
||||
elsif current_adapter?(:SQLite3Adapter) && ActiveRecord::Base.connection.supports_partial_index?
|
||||
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index", where: "rating > 10"', index_definition
|
||||
index_definition = dump_table_schema("companies").split(/\n/).grep(/t\.index.*company_partial_index/).first.strip
|
||||
if current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter) && ActiveRecord::Base.connection.supports_partial_index?
|
||||
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index", where: "(rating > 10)"', index_definition
|
||||
else
|
||||
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index"', index_definition
|
||||
end
|
||||
|
@ -248,9 +244,9 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_schema_dumps_index_type
|
||||
output = standard_dump
|
||||
assert_match %r{t\.index \["awesome"\], name: "index_key_tests_on_awesome", type: :fulltext}, output
|
||||
assert_match %r{t\.index \["pizza"\], name: "index_key_tests_on_pizza", using: :btree}, output
|
||||
output = dump_table_schema "key_tests"
|
||||
assert_match %r{t\.index \["awesome"\], name: "index_key_tests_on_awesome", type: :fulltext$}, output
|
||||
assert_match %r{t\.index \["pizza"\], name: "index_key_tests_on_pizza"$}, output
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -277,7 +273,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
|
||||
def test_schema_dump_expression_indices
|
||||
index_definition = dump_table_schema("companies").split(/\n/).grep(/t\.index.*company_expression_index/).first.strip
|
||||
assert_equal 't.index "lower((name)::text)", name: "company_expression_index", using: :btree', index_definition
|
||||
assert_equal 't.index "lower((name)::text)", name: "company_expression_index"', index_definition
|
||||
end
|
||||
|
||||
def test_schema_dump_interval_type
|
||||
|
|
|
@ -201,7 +201,7 @@ ActiveRecord::Schema.define do
|
|||
t.integer :account_id
|
||||
t.string :description, default: ""
|
||||
t.index [:firm_id, :type, :rating], name: "company_index", length: { type: 10 }, order: { rating: :desc }
|
||||
t.index [:firm_id, :type], name: "company_partial_index", where: "rating > 10"
|
||||
t.index [:firm_id, :type], name: "company_partial_index", where: "(rating > 10)"
|
||||
t.index :name, name: "company_name_index", using: :btree
|
||||
t.index "lower(name)", name: "company_expression_index" if supports_expression_index?
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue