Skip to content

Instantly share code, notes, and snippets.

@zegomesjf
Created April 10, 2019 18:41
Show Gist options
  • Save zegomesjf/8a6099118decf388c69e90636c89d097 to your computer and use it in GitHub Desktop.
Save zegomesjf/8a6099118decf388c69e90636c89d097 to your computer and use it in GitHub Desktop.
generates migration to change columns from integer to bigint
connection ||= ActiveRecord::Base.connection
tables = connection.tables
pks_to_be_changed = ''
fks_to_be_changed = ''
tables.each do |table|
connection.columns(table)
pk = connection.primary_key(table)
create_bigint_pk = false
connection.columns(table).each do |column|
if column.name == pk && column.type == :integer && column.limit == 4
pks_to_be_changed << "change_column :#{table}, :#{pk}, :bigint\n"
end
if column.name.ends_with?('_id') && column.type == :integer && column.limit == 4
fks_to_be_changed << "change_column :#{table}, :#{column.name}, :bigint\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment