2020-03-24 16:45:27 +01:00
|
|
|
# frozen_string_literal:true
|
|
|
|
|
2023-02-24 17:26:55 +01:00
|
|
|
# Wallet data must be attached to InvoicingProfile because we must keep these data after the user has delete his account
|
2020-03-24 16:45:27 +01:00
|
|
|
class MigrateWalletToInvoicingProfile < ActiveRecord::Migration[4.2]
|
2019-06-03 16:00:09 +02:00
|
|
|
def up
|
|
|
|
Wallet.all.each do |w|
|
|
|
|
user = User.find(w.user_id)
|
2023-02-24 17:26:55 +01:00
|
|
|
w.update(
|
2019-06-03 16:00:09 +02:00
|
|
|
invoicing_profile_id: user.invoicing_profile.id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
WalletTransaction.all.each do |wt|
|
|
|
|
user = User.find(wt.user_id)
|
2023-02-24 17:26:55 +01:00
|
|
|
wt.update(
|
2019-06-03 16:00:09 +02:00
|
|
|
invoicing_profile_id: user.invoicing_profile.id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
Wallet.all.each do |w|
|
|
|
|
invoicing_profile = User.find(w.invoicing_profile_id)
|
2023-02-24 17:26:55 +01:00
|
|
|
w.update(
|
2019-06-03 16:00:09 +02:00
|
|
|
user_id: invoicing_profile.user_id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
WalletTransaction.all.each do |wt|
|
|
|
|
invoicing_profile = User.find(wt.invoicing_profile_id)
|
2023-02-24 17:26:55 +01:00
|
|
|
wt.update(
|
2019-06-03 16:00:09 +02:00
|
|
|
user_id: invoicing_profile.user_id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|