|
|
@ -5,7 +5,8 @@ class IdsToBigints < ActiveRecord::Migration[5.1] |
|
|
|
|
|
|
|
|
|
|
|
disable_ddl_transaction! |
|
|
|
disable_ddl_transaction! |
|
|
|
|
|
|
|
|
|
|
|
INCLUDED_COLUMNS = [ |
|
|
|
def migrate_columns(to_type) |
|
|
|
|
|
|
|
included_columns = [ |
|
|
|
[:account_domain_blocks, :account_id], |
|
|
|
[:account_domain_blocks, :account_id], |
|
|
|
[:account_domain_blocks, :id], |
|
|
|
[:account_domain_blocks, :id], |
|
|
|
[:accounts, :id], |
|
|
|
[:accounts, :id], |
|
|
@ -66,9 +67,8 @@ class IdsToBigints < ActiveRecord::Migration[5.1] |
|
|
|
[:web_settings, :id], |
|
|
|
[:web_settings, :id], |
|
|
|
[:web_settings, :user_id], |
|
|
|
[:web_settings, :user_id], |
|
|
|
] |
|
|
|
] |
|
|
|
INCLUDED_COLUMNS << [:deprecated_preview_cards, :id] if table_exists?(:deprecated_preview_cards) |
|
|
|
included_columns << [:deprecated_preview_cards, :id] if table_exists?(:deprecated_preview_cards) |
|
|
|
|
|
|
|
|
|
|
|
def migrate_columns(to_type) |
|
|
|
|
|
|
|
# Print out a warning that this will probably take a while. |
|
|
|
# Print out a warning that this will probably take a while. |
|
|
|
say '' |
|
|
|
say '' |
|
|
|
say 'WARNING: This migration may take a *long* time for large instances' |
|
|
|
say 'WARNING: This migration may take a *long* time for large instances' |
|
|
@ -86,7 +86,7 @@ class IdsToBigints < ActiveRecord::Migration[5.1] |
|
|
|
sleep 1 |
|
|
|
sleep 1 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
tables = INCLUDED_COLUMNS.map(&:first).uniq |
|
|
|
tables = included_columns.map(&:first).uniq |
|
|
|
table_sizes = {} |
|
|
|
table_sizes = {} |
|
|
|
|
|
|
|
|
|
|
|
# Sort tables by their size |
|
|
|
# Sort tables by their size |
|
|
@ -94,7 +94,7 @@ class IdsToBigints < ActiveRecord::Migration[5.1] |
|
|
|
table_sizes[table] = estimate_rows_in_table(table) |
|
|
|
table_sizes[table] = estimate_rows_in_table(table) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
ordered_columns = INCLUDED_COLUMNS.sort_by do |col_parts| |
|
|
|
ordered_columns = included_columns.sort_by do |col_parts| |
|
|
|
[-table_sizes[col_parts.first], col_parts.last] |
|
|
|
[-table_sizes[col_parts.first], col_parts.last] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|