class ActiveRecord::Migration::Compatibility::V5_0

def add_column(table_name, column_name, type, **options)

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

def add_reference(table_name, ref_name, **options)

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

def compatible_table_definition(t)

def compatible_table_definition(t)
  class << t
    prepend TableDefinition
  end
  super
end

def create_join_table(table_1, table_2, column_options: {}, **options)

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

def create_table(table_name, **options)

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