@@ -24,6 +24,7 @@ defmodule DatabaseMigration do
24
24
alias Algora.Bounties.Claim
25
25
alias Algora.Payments.Account
26
26
alias Algora.Payments.Customer
27
+ alias Algora.Payments.PaymentMethod
27
28
alias Algora.Payments.Transaction
28
29
alias Algora.Workspace.Installation
29
30
alias Algora.Workspace.Ticket
@@ -44,7 +45,8 @@ defmodule DatabaseMigration do
44
45
"BountyTransfer" => "transactions" ,
45
46
"GithubInstallation" => "installations" ,
46
47
"StripeAccount" => "accounts" ,
47
- "StripeCustomer" => "customers"
48
+ "StripeCustomer" => "customers" ,
49
+ "StripePaymentMethod" => "payment_methods"
48
50
}
49
51
50
52
@ schema_mappings % {
@@ -61,11 +63,13 @@ defmodule DatabaseMigration do
61
63
"BountyTransfer" => Transaction ,
62
64
"GithubInstallation" => Installation ,
63
65
"StripeAccount" => Account ,
64
- "StripeCustomer" => Customer
66
+ "StripeCustomer" => Customer ,
67
+ "StripePaymentMethod" => PaymentMethod
65
68
}
66
69
67
70
@ backfilled_tables [
68
71
"accounts" ,
72
+ "payment_methods" ,
69
73
"customers" ,
70
74
"installations" ,
71
75
"repositories" ,
@@ -492,6 +496,26 @@ defmodule DatabaseMigration do
492
496
}
493
497
end
494
498
499
+ defp transform ( "StripePaymentMethod" , row , db ) do
500
+ customer = db |> Map . get ( "StripeCustomer" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == row [ "customer_id" ] ) )
501
+
502
+ if ! customer do
503
+ raise "StripeCustomer not found: #{ inspect ( row ) } "
504
+ end
505
+
506
+ % {
507
+ "id" => row [ "id" ] ,
508
+ "provider" => "stripe" ,
509
+ "provider_id" => row [ "stripe_id" ] ,
510
+ "provider_meta" => nil ,
511
+ "provider_customer_id" => customer [ "stripe_id" ] ,
512
+ "is_default" => row [ "is_default" ] ,
513
+ "customer_id" => row [ "customer_id" ] ,
514
+ "inserted_at" => row [ "created_at" ] ,
515
+ "updated_at" => row [ "updated_at" ]
516
+ }
517
+ end
518
+
495
519
defp transform ( _ , _row , _db ) , do: nil
496
520
497
521
def process_dump ( input_file , output_file ) do
0 commit comments