Module: ActiveRecord::Migration::Compatibility::FourTwoShared

Included in:
Legacy, V4_2
Defined in:
activerecord/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


56
57
58
59
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 56

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

#add_timestamps(**options) ⇒ Object


62
63
64
65
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 62

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

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


43
44
45
46
47
48
49
50
51
52
53
54
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 43

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


30
31
32
33
34
35
36
37
38
39
40
41
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 30

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


67
68
69
70
71
72
73
74
75
76
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 67

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


78
79
80
81
82
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 78

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