@@ -21,6 +21,7 @@ defmodule DatabaseMigration do
21
21
"""
22
22
alias Algora.Accounts.User
23
23
alias Algora.Bounties.Bounty
24
+ alias Algora.Bounties.Claim
24
25
alias Algora.Payments.Transaction
25
26
alias Algora.Workspace.Ticket
26
27
@@ -35,9 +36,9 @@ defmodule DatabaseMigration do
35
36
"GithubPullRequest" => nil ,
36
37
"Bounty" => "bounties" ,
37
38
"Reward" => nil ,
39
+ "Claim" => "claims" ,
38
40
"BountyCharge" => "transactions" ,
39
- "BountyTransfer" => "transactions" ,
40
- "Claim" => nil
41
+ "BountyTransfer" => "transactions"
41
42
}
42
43
43
44
@ schema_mappings % {
@@ -49,9 +50,9 @@ defmodule DatabaseMigration do
49
50
"GithubPullRequest" => nil ,
50
51
"Bounty" => Bounty ,
51
52
"Reward" => nil ,
53
+ "Claim" => Claim ,
52
54
"BountyCharge" => Transaction ,
53
- "BountyTransfer" => Transaction ,
54
- "Claim" => nil
55
+ "BountyTransfer" => Transaction
55
56
}
56
57
57
58
@ backfilled_tables [ "repositories" , "transactions" , "bounties" , "tickets" , "users" ]
@@ -294,6 +295,38 @@ defmodule DatabaseMigration do
294
295
}
295
296
end
296
297
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
+
297
330
defp transform ( "BountyCharge" , row , db ) do
298
331
user = db |> Map . get ( "Org" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == row [ "org_id" ] ) )
299
332
0 commit comments