@@ -24,6 +24,7 @@ defmodule DatabaseMigration do
24
24
alias Algora.Bounties.Attempt
25
25
alias Algora.Bounties.Bounty
26
26
alias Algora.Bounties.Claim
27
+ alias Algora.Bounties.Tip
27
28
alias Algora.Organizations.Member
28
29
alias Algora.Payments.Account
29
30
alias Algora.Payments.Customer
@@ -49,6 +50,7 @@ defmodule DatabaseMigration do
49
50
{ "Claim" , Claim } ,
50
51
{ "BountyCharge" , Transaction } ,
51
52
{ "BountyTransfer" , Transaction } ,
53
+ { "BountyTransfer" , Tip } ,
52
54
{ "GithubInstallation" , Installation } ,
53
55
{ "StripeAccount" , Account } ,
54
56
{ "StripeCustomer" , Customer } ,
@@ -65,6 +67,7 @@ defmodule DatabaseMigration do
65
67
"claims" ,
66
68
"attempts" ,
67
69
"bounties" ,
70
+ "tips" ,
68
71
"tickets" ,
69
72
"members" ,
70
73
"identities" ,
@@ -487,6 +490,40 @@ defmodule DatabaseMigration do
487
490
}
488
491
end
489
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
+
512
+ 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
+ }
524
+ end
525
+ end
526
+
490
527
defp transform ( { "GithubInstallation" , Installation } , row , _db ) do
491
528
% {
492
529
"id" => row [ "id" ] ,
@@ -928,8 +965,8 @@ defmodule DatabaseMigration do
928
965
output_file = ".local/prod_db_new.sql"
929
966
930
967
if File . exists? ( input_file ) or File . exists? ( output_file ) do
931
- # IO.puts("Processing dump...")
932
- # :ok = process_dump(input_file, output_file)
968
+ IO . puts ( "Processing dump..." )
969
+ :ok = process_dump ( input_file , output_file )
933
970
934
971
IO . puts ( "Clearing tables..." )
935
972
:ok = clear_tables! ( )
0 commit comments