Class: ActiveRecord::Migration::Compatibility::V5_0

Inherits:
V5_1 show all
Defined in:
lib/active_record/migration/compatibility.rb

Direct Known Subclasses

V4_2

Defined Under Namespace

Modules: TableDefinition

Instance Method Summary collapse

Methods inherited from V5_1

#change_column

Methods inherited from V5_2

#add_timestamps

Methods inherited from V6_1

#change_column

Methods inherited from V7_0

#add_foreign_key, #add_index, #change_column, #change_column_null, #disable_extension, #rename_table

Instance Method Details

#add_column(table_name, column_name, type, **options) ⇒ Object



387
388
389
390
391
392
393
394
395
# File 'lib/active_record/migration/compatibility.rb', line 387

def add_column(table_name, column_name, type, **options)
  if type == :primary_key
    type = :integer
    options[:primary_key] = true
  elsif type == :datetime
    options[:precision] ||= nil
  end
  super
end

#add_reference(table_name, ref_name, **options) ⇒ Object Also known as: add_belongs_to



397
398
399
# File 'lib/active_record/migration/compatibility.rb', line 397

def add_reference(table_name, ref_name, **options)
  super(table_name, ref_name, type: :integer, **options)
end

#create_join_table(table_1, table_2, column_options: {}, **options) ⇒ Object



382
383
384
385
# File 'lib/active_record/migration/compatibility.rb', line 382

def create_join_table(table_1, table_2, column_options: {}, **options)
  column_options.reverse_merge!(type: :integer)
  super
end

#create_table(table_name, **options) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/active_record/migration/compatibility.rb', line 359

def create_table(table_name, **options)
  if connection.adapter_name == "PostgreSQL"
    if options[:id] == :uuid && !options.key?(:default)
      options[:default] = "uuid_generate_v4()"
    end
  end

  unless ["Mysql2", "Trilogy"].include?(connection.adapter_name) && options[:id] == :bigint
    if [:integer, :bigint].include?(options[:id]) && !options.key?(:default)
      options[:default] = nil
    end
  end

  # Since 5.1 PostgreSQL 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 options.key?(:id)
    options[:id] = :integer
  end

  super
end