aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r--activerecord/lib/active_record/migration/compatibility.rb19
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