Skip to content

Commit d7f2cd6

Browse files
committed
add transform for Claim
1 parent 0b98041 commit d7f2cd6

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

scripts/database_migration.exs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ defmodule DatabaseMigration do
2121
"""
2222
alias Algora.Accounts.User
2323
alias Algora.Bounties.Bounty
24+
alias Algora.Bounties.Claim
2425
alias Algora.Payments.Transaction
2526
alias Algora.Workspace.Ticket
2627

@@ -35,9 +36,9 @@ defmodule DatabaseMigration do
3536
"GithubPullRequest" => nil,
3637
"Bounty" => "bounties",
3738
"Reward" => nil,
39+
"Claim" => "claims",
3840
"BountyCharge" => "transactions",
39-
"BountyTransfer" => "transactions",
40-
"Claim" => nil
41+
"BountyTransfer" => "transactions"
4142
}
4243

4344
@schema_mappings %{
@@ -49,9 +50,9 @@ defmodule DatabaseMigration do
4950
"GithubPullRequest" => nil,
5051
"Bounty" => Bounty,
5152
"Reward" => nil,
53+
"Claim" => Claim,
5254
"BountyCharge" => Transaction,
53-
"BountyTransfer" => Transaction,
54-
"Claim" => nil
55+
"BountyTransfer" => Transaction
5556
}
5657

5758
@backfilled_tables ["repositories", "transactions", "bounties", "tickets", "users"]
@@ -294,6 +295,38 @@ defmodule DatabaseMigration do
294295
}
295296
end
296297

298+
defp transform("Claim", row, db) do
299+
bounty = db |> Map.get("Bounty", []) |> Enum.find(&(&1["id"] == row["bounty_id"]))
300+
301+
task = db |> Map.get("Task", []) |> Enum.find(&(&1["id"] == bounty["task_id"]))
302+
303+
github_user = db |> Map.get("GithubUser", []) |> Enum.find(&(&1["id"] == row["github_user_id"]))
304+
305+
user = db |> Map.get("User", []) |> Enum.find(&(&1["id"] == github_user["user_id"]))
306+
307+
# TODO: this might be null
308+
github_pull_request =
309+
db |> Map.get("GithubPullRequest", []) |> Enum.find(&(&1["id"] == row["github_pull_request_id"]))
310+
311+
if !task || !user do
312+
raise "Task or User not found: #{inspect(row)}"
313+
end
314+
315+
%{
316+
"id" => row["id"],
317+
"status" => nil,
318+
"type" => nil,
319+
"url" => row["github_url"],
320+
"group_id" => nil,
321+
"group_share" => nil,
322+
"source_id" => github_pull_request["task_id"],
323+
"target_id" => task["id"],
324+
"user_id" => user["id"],
325+
"inserted_at" => row["created_at"],
326+
"updated_at" => row["updated_at"]
327+
}
328+
end
329+
297330
defp transform("BountyCharge", row, db) do
298331
user = db |> Map.get("Org", []) |> Enum.find(&(&1["id"] == row["org_id"]))
299332

0 commit comments

Comments
 (0)