Skip to content

Commit

Permalink
move migration script to rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead committed Jul 21, 2024
1 parent c9be854 commit 75ccb35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,6 @@ def up
add_column :ticket_purchases, :amount_paid_cents, :integer, default: 0

TicketPurchase.reset_column_information

TicketPurchase.find_each do |purchase|
converted_amount = CurrencyConversion.convert_currency(
purchase.conference,
purchase.price,
purchase.price_currency,
purchase.currency
)

purchase.update_column(:amount_paid_cents, converted_amount.fractional)
end
end

def down
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/migrate_config.rake
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,18 @@ namespace :data do

puts "Migrated config/config.yml to .env.#{Rails.env}"
end

task :update_ticket_purchase_currency do
TicketPurchase.find_each do |purchase|
converted_amount = CurrencyConversion.convert_currency(
purchase.conference,
purchase.ticket.price_cents,
purchase.price_currency,
purchase.currency
)

purchase.update_column(:amount_paid_cents, converted_amount.fractional)
end
end
end
end

0 comments on commit 75ccb35

Please sign in to comment.