Skip to content

Commit 8eb41fb

Browse files
committed
add transform for Attempt
1 parent 6e12eb2 commit 8eb41fb

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

scripts/database_migration.exs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ defmodule DatabaseMigration do
2020
- Run the script using: elixir scripts/database_migration.exs
2121
"""
2222
alias Algora.Accounts.User
23+
alias Algora.Bounties.Attempt
2324
alias Algora.Bounties.Bounty
2425
alias Algora.Bounties.Claim
2526
alias Algora.Organizations.Member
@@ -42,6 +43,7 @@ defmodule DatabaseMigration do
4243
"GithubPullRequest" => nil,
4344
"Bounty" => "bounties",
4445
"Reward" => nil,
46+
"Attempt" => "attempts",
4547
"Claim" => "claims",
4648
"BountyCharge" => "transactions",
4749
"BountyTransfer" => "transactions",
@@ -61,6 +63,7 @@ defmodule DatabaseMigration do
6163
"GithubPullRequest" => nil,
6264
"Bounty" => Bounty,
6365
"Reward" => nil,
66+
"Attempt" => Attempt,
6467
"Claim" => Claim,
6568
"BountyCharge" => Transaction,
6669
"BountyTransfer" => Transaction,
@@ -78,6 +81,7 @@ defmodule DatabaseMigration do
7881
"repositories",
7982
"transactions",
8083
"claims",
84+
"attempts",
8185
"bounties",
8286
"tickets",
8387
"members",
@@ -307,10 +311,6 @@ defmodule DatabaseMigration do
307311
defp transform("GithubUser", _row, _db), do: nil
308312

309313
defp transform("OrgMember", row, _db) do
310-
if row["role"] not in ["admin", "mod", "expert"] do
311-
raise "OrgMember has unknown role: #{inspect(row)}"
312-
end
313-
314314
%{
315315
"id" => row["id"],
316316
"org_id" => row["org_id"],
@@ -337,6 +337,32 @@ defmodule DatabaseMigration do
337337
}
338338
end
339339

340+
defp transform("Attempt", row, db) do
341+
bounty = db |> Map.get("Bounty", []) |> Enum.find(&(&1["id"] == row["bounty_id"]))
342+
343+
github_user = db |> Map.get("GithubUser", []) |> Enum.find(&(&1["id"] == row["github_user_id"]))
344+
345+
user = db |> Map.get("User", []) |> Enum.find(&(&1["id"] == github_user["user_id"]))
346+
347+
if !bounty do
348+
raise "Bounty not found: #{inspect(row)}"
349+
end
350+
351+
if !user do
352+
raise "User not found: #{inspect(row)}"
353+
end
354+
355+
%{
356+
"id" => row["id"],
357+
"status" => row["status"],
358+
"warnings_count" => row["warnings_count"],
359+
"ticket_id" => bounty["task_id"],
360+
"user_id" => user["id"],
361+
"inserted_at" => row["created_at"],
362+
"updated_at" => row["updated_at"]
363+
}
364+
end
365+
340366
defp transform("Claim", row, db) do
341367
bounty = db |> Map.get("Bounty", []) |> Enum.find(&(&1["id"] == row["bounty_id"]))
342368

scripts/v1-progress.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
- github_user_id: -1
2929
- org_id: -1
3030
- "Attempt":
31-
- id: 0
32-
- created_at: 0
33-
- updated_at: 0
34-
- bounty_id: 0
35-
- github_user_id: 0
36-
- warnings_count: 0
37-
- status: 0
31+
- id: 1
32+
- created_at: 1
33+
- updated_at: 1
34+
- bounty_id: 1
35+
- github_user_id: 1
36+
- warnings_count: 1
37+
- status: 1
3838
- "Bid":
3939
- id: -1
4040
- created_at: -1

scripts/v2-progress.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
- payout_speed: -1
1919
- default_currency: -1
2020
- attempts:
21-
- id: 0
22-
- status: 0
23-
- warnings_count: 0
24-
- ticket_id: 0
25-
- user_id: 0
26-
- inserted_at: 0
27-
- updated_at: 0
21+
- id: 1
22+
- status: 1
23+
- warnings_count: 1
24+
- ticket_id: 1
25+
- user_id: 1
26+
- inserted_at: 1
27+
- updated_at: 1
2828
- bounties:
2929
- id: 1
3030
- amount: 1

0 commit comments

Comments
 (0)