Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer to place a table options before force: :cascade #28005

Merged
merged 1 commit into from
Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions activerecord/lib/active_record/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ def table(table, stream)
else
tbl.print ", id: false"
end
tbl.print ", force: :cascade"

table_options = @connection.table_options(table)
if table_options.present?
tbl.print ", #{format_options(table_options)}"
end

tbl.puts " do |t|"
tbl.puts ", force: :cascade do |t|"

# then dump all non-primary key columns
columns.each do |column|
Expand Down
8 changes: 4 additions & 4 deletions activerecord/test/cases/adapters/mysql2/table_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ def teardown
test "table options with ENGINE" do
@connection.create_table "mysql_table_options", force: true, options: "ENGINE=MyISAM"
output = dump_table_schema("mysql_table_options")
options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{ENGINE=MyISAM}, options
end

test "table options with ROW_FORMAT" do
@connection.create_table "mysql_table_options", force: true, options: "ROW_FORMAT=REDUNDANT"
output = dump_table_schema("mysql_table_options")
options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{ROW_FORMAT=REDUNDANT}, options
end

test "table options with CHARSET" do
@connection.create_table "mysql_table_options", force: true, options: "CHARSET=utf8mb4"
output = dump_table_schema("mysql_table_options")
options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{CHARSET=utf8mb4}, options
end

test "table options with COLLATE" do
@connection.create_table "mysql_table_options", force: true, options: "COLLATE=utf8mb4_bin"
output = dump_table_schema("mysql_table_options")
options = %r{create_table "mysql_table_options", force: :cascade, options: "(?<options>.*)"}.match(output)[:options]
options = %r{create_table "mysql_table_options", options: "(?<options>.*)"}.match(output)[:options]
assert_match %r{COLLATE=utf8mb4_bin}, options
end
end
2 changes: 1 addition & 1 deletion activerecord/test/cases/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_schema_dump_with_comments

# And check that these changes are reflected in dump
output = dump_table_schema "commenteds"
assert_match %r[create_table "commenteds",.+\s+comment: "A table with comment"], output
assert_match %r[create_table "commenteds",.*\s+comment: "A table with comment"], output
assert_match %r[t\.string\s+"name",\s+comment: "Comment should help clarify the column purpose"], output
assert_match %r[t\.string\s+"obvious"\n], output
assert_match %r[t\.string\s+"content",\s+comment: "Whoa, content describes itself!"], output
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/primary_keys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class Widget < ActiveRecord::Base
test "schema dump primary key with serial/integer" do
@connection.create_table(:widgets, id: @pk_type, force: true)
schema = dump_table_schema "widgets"
assert_match %r{create_table "widgets", id: :#{@pk_type}, force: :cascade}, schema
assert_match %r{create_table "widgets", id: :#{@pk_type}, }, schema
end

if current_adapter?(:Mysql2Adapter)
Expand All @@ -447,7 +447,7 @@ class Widget < ActiveRecord::Base
assert column.unsigned?

schema = dump_table_schema "widgets"
assert_match %r{create_table "widgets", id: :integer, unsigned: true, force: :cascade}, schema
assert_match %r{create_table "widgets", id: :integer, unsigned: true, }, schema
end

test "bigint primary key with unsigned" do
Expand All @@ -459,7 +459,7 @@ class Widget < ActiveRecord::Base
assert column.unsigned?

schema = dump_table_schema "widgets"
assert_match %r{create_table "widgets", id: :bigint, unsigned: true, force: :cascade}, schema
assert_match %r{create_table "widgets", id: :bigint, unsigned: true, }, schema
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/schema_dumper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_schema_dump

def test_schema_dump_uses_force_cascade_on_create_table
output = dump_table_schema "authors"
assert_match %r{create_table "authors", force: :cascade}, output
assert_match %r{create_table "authors",.* force: :cascade}, output
end

def test_schema_dump_excludes_sqlite_sequence
Expand Down