diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-23 13:18:11 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-23 13:55:47 +0900 |
commit | dfe6939e16bdcf854d32b61933d55fe313ac49fb (patch) | |
tree | 22611dac14c6dab9845bc224e9941c9c048404c0 /activerecord/test/cases/migration | |
parent | c371eeffb37fc35adf261f9da52a5517826b3605 (diff) | |
download | rails-dfe6939e16bdcf854d32b61933d55fe313ac49fb.tar.gz rails-dfe6939e16bdcf854d32b61933d55fe313ac49fb.tar.bz2 rails-dfe6939e16bdcf854d32b61933d55fe313ac49fb.zip |
Adding legacy primary key should be compatible
Currently implicit legacy primary key is compatible, but adding explicit
legacy primary key is not compatible. It should also be fixed.
Fixes #30664.
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r-- | activerecord/test/cases/migration/compatibility_test.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/compatibility_test.rb b/activerecord/test/cases/migration/compatibility_test.rb index e1311c0f21..1ae15eb439 100644 --- a/activerecord/test/cases/migration/compatibility_test.rb +++ b/activerecord/test/cases/migration/compatibility_test.rb @@ -199,6 +199,57 @@ class LegacyPrimaryKeyTest < ActiveRecord::TestCase assert_match %r{create_table "legacy_primary_keys", id: :integer, default: nil}, schema end + if current_adapter?(:Mysql2Adapter, :PostgreSQLAdapter) + def test_legacy_primary_key_in_create_table_should_be_integer + @migration = Class.new(ActiveRecord::Migration[5.0]) { + def change + create_table :legacy_primary_keys, id: false do |t| + t.primary_key :id + end + end + }.new + + @migration.migrate(:up) + + schema = dump_table_schema "legacy_primary_keys" + assert_match %r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}, schema + end + + def test_legacy_primary_key_in_change_table_should_be_integer + @migration = Class.new(ActiveRecord::Migration[5.0]) { + def change + create_table :legacy_primary_keys, id: false do |t| + t.integer :dummy + end + change_table :legacy_primary_keys do |t| + t.primary_key :id + end + end + }.new + + @migration.migrate(:up) + + schema = dump_table_schema "legacy_primary_keys" + assert_match %r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}, schema + end + + def test_add_column_with_legacy_primary_key_should_be_integer + @migration = Class.new(ActiveRecord::Migration[5.0]) { + def change + create_table :legacy_primary_keys, id: false do |t| + t.integer :dummy + end + add_column :legacy_primary_keys, :id, :primary_key + end + }.new + + @migration.migrate(:up) + + schema = dump_table_schema "legacy_primary_keys" + assert_match %r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}, schema + end + end + def test_legacy_join_table_foreign_keys_should_be_integer @migration = Class.new(ActiveRecord::Migration[5.0]) { def change |