class ChangeIdsFromIntegerToBigint < ActiveRecord::Migration[5.1] def up do_migrate :integer, :bigint end def down do_migrate :bigint, :integer end private def do_migrate(type_from, type_to) ApplicationRecord.connection.tables.each do |table| begin klass = table.classify.constantize klass.columns.each do |column| next unless column.name =~ /\Aid\z|_id\z/ && column.type == type_from puts "#{table}, #{column.name}, #{column.type}, #{column.default.inspect}, #{column.null}" change_column table, column.name, type_to, default: column.default, null: column.null end rescue NameError => e # ignore end end end end