Class: ActiveRecord::Migration::Compatibility::V4_2

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

Defined Under Namespace

Modules: TableDefinition

Instance Method Summary collapse

Instance Method Details

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


115
116
117
118
# File 'lib/active_record/migration/compatibility.rb', line 115

def add_reference(*, **options)
  options[:index] ||= false
  super
end

#add_timestamps(_, **options) ⇒ Object


121
122
123
124
# File 'lib/active_record/migration/compatibility.rb', line 121

def add_timestamps(_, **options)
  options[:null] = true if options[:null].nil?
  super
end

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


102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/active_record/migration/compatibility.rb', line 102

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

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


89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/active_record/migration/compatibility.rb', line 89

def create_table(table_name, options = {})
  if block_given?
    super(table_name, options) do |t|
      class << t
        prepend TableDefinition
      end
      yield t
    end
  else
    super
  end
end

#index_exists?(table_name, column_name, options = {}) ⇒ Boolean

Returns:

  • (Boolean)

126
127
128
129
130
131
132
133
134
135
# File 'lib/active_record/migration/compatibility.rb', line 126

def index_exists?(table_name, column_name, options = {})
  column_names = Array(column_name).map(&:to_s)
  options[:name] =
    if options[:name].present?
      options[:name].to_s
    else
      index_name(table_name, column: column_names)
    end
  super
end

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


137
138
139
140
141
# File 'lib/active_record/migration/compatibility.rb', line 137

def remove_index(table_name, options = {})
  options = { column: options } unless options.is_a?(Hash)
  options[:name] = index_name_for_remove(table_name, options)
  super(table_name, options)
end