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/lib/active_record/migration/compatibility.rb | |
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/lib/active_record/migration/compatibility.rb')
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index 87c1c58aff..92993d64a7 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -20,6 +20,11 @@ module ActiveRecord class V5_0 < V5_1 module TableDefinition + def primary_key(name, type = :primary_key, **options) + type = :integer if type == :primary_key + super + end + def references(*args, **options) super(*args, type: :integer, **options) end @@ -86,6 +91,20 @@ module ActiveRecord end end + def add_column(table_name, column_name, type, options = {}) + if type == :primary_key + case adapter_name + when "PostgreSQL" + type = :serial + when "Mysql2" + type = :integer + options[:auto_increment] = true + end + options[:primary_key] = true + end + super + end + def add_reference(table_name, ref_name, **options) super(table_name, ref_name, type: :integer, **options) end |