Created
April 10, 2019 18:41
-
-
Save zegomesjf/8a6099118decf388c69e90636c89d097 to your computer and use it in GitHub Desktop.
generates migration to change columns from integer to bigint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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