Skip to content

Commit 3efc3ea

Browse files
committed
add transform for {"BountyTransfer", Tip}
1 parent 1609c7b commit 3efc3ea

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

scripts/database_migration.exs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ defmodule DatabaseMigration do
2424
alias Algora.Bounties.Attempt
2525
alias Algora.Bounties.Bounty
2626
alias Algora.Bounties.Claim
27+
alias Algora.Bounties.Tip
2728
alias Algora.Organizations.Member
2829
alias Algora.Payments.Account
2930
alias Algora.Payments.Customer
@@ -49,6 +50,7 @@ defmodule DatabaseMigration do
4950
{"Claim", Claim},
5051
{"BountyCharge", Transaction},
5152
{"BountyTransfer", Transaction},
53+
{"BountyTransfer", Tip},
5254
{"GithubInstallation", Installation},
5355
{"StripeAccount", Account},
5456
{"StripeCustomer", Customer},
@@ -65,6 +67,7 @@ defmodule DatabaseMigration do
6567
"claims",
6668
"attempts",
6769
"bounties",
70+
"tips",
6871
"tickets",
6972
"members",
7073
"identities",
@@ -487,6 +490,40 @@ defmodule DatabaseMigration do
487490
}
488491
end
489492

493+
defp transform({"BountyTransfer", Tip}, row, db) do
494+
claim = db |> Map.get("Claim", []) |> Enum.find(&(&1["id"] == row["claim_id"]))
495+
496+
github_user = db |> Map.get("GithubUser", []) |> Enum.find(&(&1["id"] == row["github_user_id"]))
497+
498+
user = db |> Map.get("User", []) |> Enum.find(&(&1["id"] == github_user["user_id"]))
499+
500+
bounty = db |> Map.get("Bounty", []) |> Enum.find(&(&1["id"] == claim["bounty_id"]))
501+
502+
amount = Money.from_integer(String.to_integer(row["amount"]), row["currency"])
503+
504+
if !bounty do
505+
raise "Bounty not found: #{inspect(row)}"
506+
end
507+
508+
if !user do
509+
raise "User not found: #{inspect(row)}"
510+
end
511+
512+
if bounty["type"] == "tip" do
513+
%{
514+
"id" => row["id"],
515+
"amount" => amount,
516+
"status" => nil,
517+
"ticket_id" => bounty["task_id"],
518+
"owner_id" => bounty["org_id"],
519+
"creator_id" => bounty["poster_id"],
520+
"recipient_id" => user["id"],
521+
"inserted_at" => bounty["created_at"],
522+
"updated_at" => bounty["updated_at"]
523+
}
524+
end
525+
end
526+
490527
defp transform({"GithubInstallation", Installation}, row, _db) do
491528
%{
492529
"id" => row["id"],
@@ -928,8 +965,8 @@ defmodule DatabaseMigration do
928965
output_file = ".local/prod_db_new.sql"
929966

930967
if File.exists?(input_file) or File.exists?(output_file) do
931-
# IO.puts("Processing dump...")
932-
# :ok = process_dump(input_file, output_file)
968+
IO.puts("Processing dump...")
969+
:ok = process_dump(input_file, output_file)
933970

934971
IO.puts("Clearing tables...")
935972
:ok = clear_tables!()

scripts/v2-progress.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@
205205
- inserted_at: -1
206206
- updated_at: -1
207207
- tips:
208-
- id: 0
209-
- amount: 0
210-
- status: 0
211-
- ticket_id: 0
212-
- owner_id: 0
213-
- creator_id: 0
214-
- recipient_id: 0
215-
- inserted_at: 0
216-
- updated_at: 0
208+
- id: 1
209+
- amount: 1
210+
- status: -2
211+
- ticket_id: 1
212+
- owner_id: 1
213+
- creator_id: 1
214+
- recipient_id: 1
215+
- inserted_at: 1
216+
- updated_at: 1
217217
- transactions:
218218
- id: 1
219219
- provider: 1

0 commit comments

Comments
 (0)