Skip to content

Commit 119f40d

Browse files
committed
add transform for StripePaymentMethod
1 parent dcb6a95 commit 119f40d

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

scripts/database_migration.exs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ defmodule DatabaseMigration do
2424
alias Algora.Bounties.Claim
2525
alias Algora.Payments.Account
2626
alias Algora.Payments.Customer
27+
alias Algora.Payments.PaymentMethod
2728
alias Algora.Payments.Transaction
2829
alias Algora.Workspace.Installation
2930
alias Algora.Workspace.Ticket
@@ -44,7 +45,8 @@ defmodule DatabaseMigration do
4445
"BountyTransfer" => "transactions",
4546
"GithubInstallation" => "installations",
4647
"StripeAccount" => "accounts",
47-
"StripeCustomer" => "customers"
48+
"StripeCustomer" => "customers",
49+
"StripePaymentMethod" => "payment_methods"
4850
}
4951

5052
@schema_mappings %{
@@ -61,11 +63,13 @@ defmodule DatabaseMigration do
6163
"BountyTransfer" => Transaction,
6264
"GithubInstallation" => Installation,
6365
"StripeAccount" => Account,
64-
"StripeCustomer" => Customer
66+
"StripeCustomer" => Customer,
67+
"StripePaymentMethod" => PaymentMethod
6568
}
6669

6770
@backfilled_tables [
6871
"accounts",
72+
"payment_methods",
6973
"customers",
7074
"installations",
7175
"repositories",
@@ -492,6 +496,26 @@ defmodule DatabaseMigration do
492496
}
493497
end
494498

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+
495519
defp transform(_, _row, _db), do: nil
496520

497521
def process_dump(input_file, output_file) do

scripts/v1-progress.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,12 @@
471471
- name: 1
472472
- region: -1
473473
- "StripePaymentMethod":
474-
- id: 0
475-
- created_at: 0
476-
- updated_at: 0
477-
- stripe_id: 0
478-
- org_id: 0
479-
- is_default: 0
474+
- id: 1
475+
- created_at: 1
476+
- updated_at: 1
477+
- stripe_id: 1
478+
- org_id: -1
479+
- is_default: 1
480480
- "StripeSubscription":
481481
- id: -1
482482
- created_at: -1

scripts/v2-progress.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@
168168
- CONSTRAINT: 0
169169
- CONSTRAINT: 0
170170
- payment_methods:
171-
- id: 0
172-
- provider: 0
173-
- provider_id: 0
174-
- provider_meta: 0
175-
- provider_customer_id: 0
176-
- is_default: 0
177-
- customer_id: 0
178-
- inserted_at: 0
179-
- updated_at: 0
171+
- id: 1
172+
- provider: 1
173+
- provider_id: 1
174+
- provider_meta: -1
175+
- provider_customer_id: 1
176+
- is_default: 1
177+
- customer_id: 1
178+
- inserted_at: 1
179+
- updated_at: 1
180180
- repositories:
181181
- id: 0
182182
- provider: 0

0 commit comments

Comments
 (0)