提交 91811514 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #30655 from kuzukuzu/fix_create_join_table_compatibility

make create_join_table compatible.
...@@ -71,6 +71,21 @@ class << t ...@@ -71,6 +71,21 @@ class << t
end end
end end
def create_join_table(table_1, table_2, column_options: {}, **options)
column_options.reverse_merge!(type: :integer)
if block_given?
super(table_1, table_2, column_options: column_options, **options) do |t|
class << t
prepend TableDefinition
end
yield t
end
else
super
end
end
def add_reference(table_name, ref_name, **options) def add_reference(table_name, ref_name, **options)
super(table_name, ref_name, type: :integer, **options) super(table_name, ref_name, type: :integer, **options)
end end
......
...@@ -199,6 +199,36 @@ def change ...@@ -199,6 +199,36 @@ def change
assert_match %r{create_table "legacy_primary_keys", id: :integer, default: nil}, schema assert_match %r{create_table "legacy_primary_keys", id: :integer, default: nil}, schema
end end
def test_legacy_join_table_foreign_keys_should_be_integer
@migration = Class.new(ActiveRecord::Migration[5.0]) {
def change
create_join_table :apples, :bananas do |t|
end
end
}.new
@migration.migrate(:up)
schema = dump_table_schema "apples_bananas"
assert_match %r{integer "apple_id", null: false}, schema
assert_match %r{integer "banana_id", null: false}, schema
end
def test_legacy_join_table_column_options_should_be_overwritten
@migration = Class.new(ActiveRecord::Migration[5.0]) {
def change
create_join_table :apples, :bananas, column_options: { type: :bigint } do |t|
end
end
}.new
@migration.migrate(:up)
schema = dump_table_schema "apples_bananas"
assert_match %r{bigint "apple_id", null: false}, schema
assert_match %r{bigint "banana_id", null: false}, schema
end
if current_adapter?(:Mysql2Adapter) if current_adapter?(:Mysql2Adapter)
def test_legacy_bigint_primary_key_should_be_auto_incremented def test_legacy_bigint_primary_key_should_be_auto_incremented
@migration = Class.new(ActiveRecord::Migration[5.0]) { @migration = Class.new(ActiveRecord::Migration[5.0]) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册