aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration
diff options
context:
space:
mode:
authorPavel Pravosud <pavel@pravosud.com>2016-05-10 15:10:46 -0700
committerJon McCartie <jon@mccartie.com>2016-12-05 11:40:32 -0800
commit3e452b12043ecfd983c6132d6eb97eb79db952b7 (patch)
tree4c6d98ed9f1a35a13ccb2f7be3d903a05a3a6ec8 /activerecord/lib/active_record/migration
parentb92ae610699f991e4616409815fa1e7f134dacc5 (diff)
downloadrails-3e452b12043ecfd983c6132d6eb97eb79db952b7.tar.gz
rails-3e452b12043ecfd983c6132d6eb97eb79db952b7.tar.bz2
rails-3e452b12043ecfd983c6132d6eb97eb79db952b7.zip
Make pg adapter use bigserial for pk by default
Diffstat (limited to 'activerecord/lib/active_record/migration')
-rw-r--r--activerecord/lib/active_record/migration/compatibility.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb
index ae45ac7157..9d3652d63b 100644
--- a/activerecord/lib/active_record/migration/compatibility.rb
+++ b/activerecord/lib/active_record/migration/compatibility.rb
@@ -104,11 +104,21 @@ module ActiveRecord
class V5_0 < V5_1
def create_table(table_name, options = {})
- if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ connection_name = self.connection.adapter_name
+ if connection_name == "PostgreSQL"
if options[:id] == :uuid && !options[:default]
options[:default] = "uuid_generate_v4()"
end
end
+
+ # Since 5.1 Postgres adapter uses bigserial type for primary
+ # keys by default and MySQL uses bigint. This compat layer makes old migrations utilize
+ # serial/int type instead -- the way it used to work before 5.1.
+ if options[:id].blank?
+ options[:id] = :integer
+ options[:auto_increment] = true
+ end
+
super
end
end