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

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

Direct Known Subclasses

V4_2

Defined Under Namespace

Modules: TableDefinition

Instance Method Summary collapse

Instance Method Details

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



75
76
77
# File 'lib/active_record/migration/compatibility.rb', line 75

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

#change_table(table_name, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/active_record/migration/compatibility.rb', line 53

def change_table(table_name, options = {})
  if block_given?
    super do |t|
      yield compatible_table_definition(t)
    end
  else
    super
  end
end

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



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/active_record/migration/compatibility.rb', line 63

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

  if block_given?
    super do |t|
      yield compatible_table_definition(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
# File 'lib/active_record/migration/compatibility.rb', line 24

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

  unless adapter_name == "Mysql2" && options[:id] == :bigint
    if [:integer, :bigint].include?(options[:id]) && !options.key?(:default)
      options[: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 options.key?(:id)
    options[:id] = :integer
  end

  if block_given?
    super do |t|
      yield compatible_table_definition(t)
    end
  else
    super
  end
end