@@ -20,6 +20,7 @@ defmodule DatabaseMigration do
20
20
- Run the script using: elixir scripts/database_migration.exs
21
21
"""
22
22
alias Algora.Accounts.User
23
+ alias Algora.Bounties.Attempt
23
24
alias Algora.Bounties.Bounty
24
25
alias Algora.Bounties.Claim
25
26
alias Algora.Organizations.Member
@@ -42,6 +43,7 @@ defmodule DatabaseMigration do
42
43
"GithubPullRequest" => nil ,
43
44
"Bounty" => "bounties" ,
44
45
"Reward" => nil ,
46
+ "Attempt" => "attempts" ,
45
47
"Claim" => "claims" ,
46
48
"BountyCharge" => "transactions" ,
47
49
"BountyTransfer" => "transactions" ,
@@ -61,6 +63,7 @@ defmodule DatabaseMigration do
61
63
"GithubPullRequest" => nil ,
62
64
"Bounty" => Bounty ,
63
65
"Reward" => nil ,
66
+ "Attempt" => Attempt ,
64
67
"Claim" => Claim ,
65
68
"BountyCharge" => Transaction ,
66
69
"BountyTransfer" => Transaction ,
@@ -78,6 +81,7 @@ defmodule DatabaseMigration do
78
81
"repositories" ,
79
82
"transactions" ,
80
83
"claims" ,
84
+ "attempts" ,
81
85
"bounties" ,
82
86
"tickets" ,
83
87
"members" ,
@@ -307,10 +311,6 @@ defmodule DatabaseMigration do
307
311
defp transform ( "GithubUser" , _row , _db ) , do: nil
308
312
309
313
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
-
314
314
% {
315
315
"id" => row [ "id" ] ,
316
316
"org_id" => row [ "org_id" ] ,
@@ -337,6 +337,32 @@ defmodule DatabaseMigration do
337
337
}
338
338
end
339
339
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
+
340
366
defp transform ( "Claim" , row , db ) do
341
367
bounty = db |> Map . get ( "Bounty" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == row [ "bounty_id" ] ) )
342
368
0 commit comments