@@ -49,8 +49,8 @@ defmodule DatabaseMigration do
49
49
{ "Attempt" , Attempt } ,
50
50
{ "Claim" , Claim } ,
51
51
{ "BountyCharge" , Transaction } ,
52
- { "BountyTransfer" , Transaction } ,
53
52
{ "BountyTransfer" , Tip } ,
53
+ { "BountyTransfer" , Transaction } ,
54
54
{ "GithubInstallation" , Installation } ,
55
55
{ "StripeAccount" , Account } ,
56
56
{ "StripeCustomer" , Customer } ,
@@ -441,21 +441,61 @@ defmodule DatabaseMigration do
441
441
}
442
442
end
443
443
444
+ defp transform ( { "BountyTransfer" , Tip } , row , db ) do
445
+ claim = db |> Map . get ( "Claim" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == row [ "claim_id" ] ) )
446
+
447
+ github_user = db |> Map . get ( "GithubUser" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == row [ "github_user_id" ] ) )
448
+
449
+ user = db |> Map . get ( "User" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == github_user [ "user_id" ] ) )
450
+
451
+ bounty = db |> Map . get ( "Bounty" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == claim [ "bounty_id" ] ) )
452
+
453
+ amount = Money . from_integer ( String . to_integer ( row [ "amount" ] ) , row [ "currency" ] )
454
+
455
+ if ! bounty do
456
+ raise "Bounty not found: #{ inspect ( row ) } "
457
+ end
458
+
459
+ if ! user do
460
+ raise "User not found: #{ inspect ( row ) } "
461
+ end
462
+
463
+ if bounty [ "type" ] == "tip" do
464
+ % {
465
+ "id" => bounty [ "id" ] <> user [ "id" ] ,
466
+ "amount" => amount ,
467
+ "status" => nil ,
468
+ "ticket_id" => bounty [ "task_id" ] ,
469
+ "owner_id" => bounty [ "org_id" ] ,
470
+ "creator_id" => bounty [ "poster_id" ] ,
471
+ "recipient_id" => user [ "id" ] ,
472
+ "inserted_at" => bounty [ "created_at" ] ,
473
+ "updated_at" => bounty [ "updated_at" ]
474
+ }
475
+ end
476
+ end
477
+
444
478
defp transform ( { "BountyTransfer" , Transaction } , row , db ) do
445
479
claim = db |> Map . get ( "Claim" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == row [ "claim_id" ] ) )
446
480
481
+ bounty = db |> Map . get ( "Bounty" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == claim [ "bounty_id" ] ) )
482
+
447
483
github_user = db |> Map . get ( "GithubUser" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == claim [ "github_user_id" ] ) )
448
484
449
485
user = db |> Map . get ( "User" , [ ] ) |> Enum . find ( & ( & 1 [ "id" ] == github_user [ "user_id" ] ) )
450
486
451
487
amount = Money . from_integer ( String . to_integer ( row [ "amount" ] ) , row [ "currency" ] )
452
488
453
- if ! claim || ! user do
454
- raise "Claim or User not found: #{ inspect ( row ) } "
489
+ if ! bounty do
490
+ raise "Bounty not found: #{ inspect ( row ) } "
491
+ end
492
+
493
+ if ! user do
494
+ raise "User not found: #{ inspect ( row ) } "
455
495
end
456
496
457
497
# TODO: add corresponding credit & debit transactions
458
- % {
498
+ row = % {
459
499
"id" => row [ "id" ] ,
460
500
"provider" => "stripe" ,
461
501
"provider_id" => row [ "transfer_id" ] ,
@@ -481,46 +521,20 @@ defmodule DatabaseMigration do
481
521
"contract_id" => nil ,
482
522
"original_contract_id" => nil ,
483
523
"timesheet_id" => nil ,
484
- "bounty_id" => claim [ "bounty_id" ] ,
524
+ "bounty_id" => nil ,
485
525
"tip_id" => nil ,
486
526
"linked_transaction_id" => nil ,
487
527
"inserted_at" => row [ "created_at" ] ,
488
528
"updated_at" => row [ "updated_at" ] ,
489
- "claim_id" => claim [ "id" ]
529
+ "claim_id" => nil
490
530
}
491
- end
492
-
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
531
512
532
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
- }
533
+ Map . put ( row , "tip_id" , bounty [ "id" ] <> user [ "id" ] )
534
+ else
535
+ row
536
+ |> Map . put ( "bounty_id" , claim [ "bounty_id" ] )
537
+ |> Map . put ( "claim_id" , claim [ "id" ] )
524
538
end
525
539
end
526
540
0 commit comments