mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Revert "Dump indexes in create_table
instead of add_index
"
This reverts commit 99801c6a7b
.
Ultimately it doesn't matter whether `add_index` or `t.index` are used
in the schema dumper in any meaningful way. There are gems out there
which hook into the old behavior for things like indexing materialized
views. Since the reverted commit doesn't seem to add much benefit,
there's no reason for us to break these gems.
This commit is contained in:
parent
7ea174e6d5
commit
d666a5a5cf
3 changed files with 16 additions and 21 deletions
|
@ -1004,13 +1004,6 @@
|
|||
|
||||
*Alex Coomans*
|
||||
|
||||
* Dump indexes in `create_table` instead of `add_index`.
|
||||
|
||||
If the adapter supports indexes in `create_table`, generated SQL is
|
||||
slightly more efficient.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
||||
* Correctly dump `:options` on `create_table` for MySQL.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
|
|
@ -178,11 +178,11 @@ HEADER
|
|||
tbl.puts
|
||||
end
|
||||
|
||||
indexes(table, tbl)
|
||||
|
||||
tbl.puts " end"
|
||||
tbl.puts
|
||||
|
||||
indexes(table, tbl)
|
||||
|
||||
tbl.rewind
|
||||
stream.print tbl.read
|
||||
rescue => e
|
||||
|
@ -198,7 +198,8 @@ HEADER
|
|||
if (indexes = @connection.indexes(table)).any?
|
||||
add_index_statements = indexes.map do |index|
|
||||
statement_parts = [
|
||||
"t.index #{index.columns.inspect}",
|
||||
"add_index #{remove_prefix_and_suffix(index.table).inspect}",
|
||||
index.columns.inspect,
|
||||
"name: #{index.name.inspect}",
|
||||
]
|
||||
statement_parts << 'unique: true' if index.unique
|
||||
|
@ -212,10 +213,11 @@ HEADER
|
|||
statement_parts << "using: #{index.using.inspect}" if index.using
|
||||
statement_parts << "type: #{index.type.inspect}" if index.type
|
||||
|
||||
" #{statement_parts.join(', ')}"
|
||||
" #{statement_parts.join(', ')}"
|
||||
end
|
||||
|
||||
stream.puts add_index_statements.sort.join("\n")
|
||||
stream.puts
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -171,24 +171,24 @@ 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 = standard_dump.split(/\n/).grep(/add_index.*companies/).first.strip
|
||||
if current_adapter?(:Mysql2Adapter, :PostgreSQLAdapter)
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", using: :btree', index_definition
|
||||
assert_equal 'add_index "companies", ["firm_id", "type", "rating"], name: "company_index", using: :btree', index_definition
|
||||
else
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index"', index_definition
|
||||
assert_equal 'add_index "companies", ["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
|
||||
index_definition = standard_dump.split(/\n/).grep(/add_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
|
||||
assert_equal 'add_index "companies", ["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
|
||||
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 't.index ["firm_id", "type"], name: "company_partial_index", where: "rating > 10"', index_definition
|
||||
assert_equal 'add_index "companies", ["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
|
||||
assert_equal 'add_index "companies", ["firm_id", "type"], name: "company_partial_index"', index_definition
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -235,8 +235,8 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
|
||||
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
|
||||
assert_match %r{add_index "key_tests", \["awesome"\], name: "index_key_tests_on_awesome", type: :fulltext}, output
|
||||
assert_match %r{add_index "key_tests", \["pizza"\], name: "index_key_tests_on_pizza", using: :btree}, output
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue