Class: ActiveRecord::Migration::Compatibility::V5_0
- Defined in:
- lib/active_record/migration/compatibility.rb
Direct Known Subclasses
Defined Under Namespace
Modules: TableDefinition
Instance Method Summary collapse
- #add_reference(table_name, ref_name, **options) ⇒ Object (also: #add_belongs_to)
- #change_table(table_name, options = {}) ⇒ Object
- #create_table(table_name, options = {}) ⇒ Object
Instance Method Details
#add_reference(table_name, ref_name, **options) ⇒ Object Also known as: add_belongs_to
69 70 71 |
# File 'lib/active_record/migration/compatibility.rb', line 69 def add_reference(table_name, ref_name, **) super(table_name, ref_name, type: :integer, **) end |
#change_table(table_name, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/active_record/migration/compatibility.rb', line 56 def change_table(table_name, = {}) if block_given? super(table_name, ) do |t| class << t prepend TableDefinition end yield t end else super end end |
#create_table(table_name, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_record/migration/compatibility.rb', line 24 def create_table(table_name, = {}) if adapter_name == "PostgreSQL" if [:id] == :uuid && !.key?(:default) [:default] = "uuid_generate_v4()" end end unless adapter_name == "Mysql2" && [:id] == :bigint if [:integer, :bigint].include?([:id]) && !.key?(:default) [:default] = nil 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. unless .key?(:id) [:id] = :integer end if block_given? super(table_name, ) do |t| class << t prepend TableDefinition end yield t end else super end end |