diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-12-12 07:42:46 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-02-07 14:21:18 +0900 |
commit | 14db455156cf822f1af738f24528200ae19efc1c (patch) | |
tree | b09bd7c9f81bee4938c116cdc7b2baa83948fb2f /activerecord/lib/active_record/migration/compatibility.rb | |
parent | 968e66b5df92e5ae88c033dc552e17b4c736874b (diff) | |
download | rails-14db455156cf822f1af738f24528200ae19efc1c.tar.gz rails-14db455156cf822f1af738f24528200ae19efc1c.tar.bz2 rails-14db455156cf822f1af738f24528200ae19efc1c.zip |
`primary_key` and `references` columns should be identical type
Follow up to #26266.
The default type of `primary_key` and `references` were changed to
`bigint` since #26266. But legacy migration and sqlite3 adapter should
keep its previous behavior.
Diffstat (limited to 'activerecord/lib/active_record/migration/compatibility.rb')
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index f6c9127d34..ffb54f5137 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -14,6 +14,13 @@ module ActiveRecord V5_1 = Current class V5_0 < V5_1 + module TableDefinition + def references(*args, **options) + super(*args, type: :integer, **options) + end + alias :belongs_to :references + end + def create_table(table_name, options = {}) if adapter_name == "PostgreSQL" if options[:id] == :uuid && !options.key?(:default) @@ -34,8 +41,35 @@ module ActiveRecord options[:id] = :integer end - super + if block_given? + super(table_name, options) do |t| + class << t + prepend TableDefinition + end + yield t + end + else + super + end end + + def change_table(table_name, options = {}) + if block_given? + super(table_name, options) do |t| + class << t + prepend TableDefinition + end + yield t + end + else + super + end + end + + def add_reference(table_name, ref_name, **options) + super(table_name, ref_name, type: :integer, **options) + end + alias :add_belongs_to :add_reference end class V4_2 < V5_0 |