Skip to content

Commit edd1afa

Browse files
committed
fix more issues
1 parent 37e08b0 commit edd1afa

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

lib/algora/bounties/schemas/bounty.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule Algora.Bounties.Bounty do
99
typed_schema "bounties" do
1010
field :amount, Algora.Types.Money
1111
field :status, Ecto.Enum, values: [:open, :cancelled, :paid]
12+
field :number, :integer, default: 0
1213

1314
belongs_to :ticket, Algora.Workspace.Ticket
1415
belongs_to :owner, User

priv/repo/migrations/20250208173814_make_provider_meta_nullable.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,12 @@ defmodule Algora.Repo.Migrations.MakeProviderMetaNullable do
3636
alter table(:tips) do
3737
modify :creator_id, :string, null: true
3838
end
39+
40+
alter table(:bounties) do
41+
add :number, :integer, null: false, default: 0
42+
end
43+
44+
drop unique_index(:bounties, [:ticket_id, :owner_id])
45+
create unique_index(:bounties, [:ticket_id, :owner_id, :number])
3946
end
4047
end

scripts/database_migration.exs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,18 @@ defmodule DatabaseMigration do
335335

336336
amount = if reward, do: Money.from_integer(String.to_integer(reward["amount"]), reward["currency"])
337337

338-
%{
339-
"id" => row["id"],
340-
"amount" => amount,
341-
"ticket_id" => row["task_id"],
342-
"owner_id" => row["org_id"],
343-
"creator_id" => row["poster_id"],
344-
"inserted_at" => row["created_at"],
345-
"updated_at" => row["updated_at"]
346-
}
338+
if row["type"] != "tip" do
339+
%{
340+
"id" => row["id"],
341+
"amount" => amount,
342+
"ticket_id" => row["task_id"],
343+
"owner_id" => row["org_id"],
344+
"creator_id" => row["poster_id"],
345+
"inserted_at" => row["created_at"],
346+
"updated_at" => row["updated_at"],
347+
"number" => row["number"]
348+
}
349+
end
347350
end
348351

349352
defp transform({"Bounty", CommandResponse}, row, _db) do
@@ -547,20 +550,23 @@ defmodule DatabaseMigration do
547550
bounty_transfer: row,
548551
bounty: bounty,
549552
claim: claim,
550-
user_id: org["id"]
553+
org: org,
554+
user_id: user_id
551555
}),
552556
maybe_create_transaction("credit", %{
553557
bounty_charge: bounty_charge,
554558
bounty_transfer: row,
555559
bounty: bounty,
556560
claim: claim,
561+
org: org,
557562
user_id: user_id
558563
}),
559564
maybe_create_transaction("transfer", %{
560565
bounty_charge: bounty_charge,
561566
bounty_transfer: row,
562567
bounty: bounty,
563568
claim: claim,
569+
org: org,
564570
user_id: user_id
565571
})
566572
],
@@ -647,6 +653,7 @@ defmodule DatabaseMigration do
647653
bounty_transfer: bounty_transfer,
648654
bounty: bounty,
649655
claim: claim,
656+
org: org,
650657
user_id: user_id
651658
}) do
652659
amount = Money.from_integer(String.to_integer(bounty_transfer["amount"]), bounty_transfer["currency"])
@@ -671,7 +678,7 @@ defmodule DatabaseMigration do
671678
"succeeded_at" => nil,
672679
"reversed_at" => nil,
673680
"group_id" => bounty_charge["id"],
674-
"user_id" => user_id,
681+
"user_id" => nil,
675682
"contract_id" => nil,
676683
"original_contract_id" => nil,
677684
"timesheet_id" => nil,
@@ -695,13 +702,22 @@ defmodule DatabaseMigration do
695702
res =
696703
case type do
697704
"transfer" ->
698-
Map.put(res, "provider_id", bounty_transfer["transfer_id"])
705+
Map.merge(res, %{
706+
"user_id" => user_id,
707+
"provider_id" => bounty_transfer["transfer_id"]
708+
})
699709

700710
"debit" ->
701-
Map.put(res, "linked_transaction_id", "cr_" <> bounty_transfer["id"])
711+
Map.merge(res, %{
712+
"user_id" => org["id"],
713+
"linked_transaction_id" => "cr_" <> bounty_transfer["id"]
714+
})
702715

703716
"credit" ->
704-
Map.put(res, "linked_transaction_id", "de_" <> bounty_transfer["id"])
717+
Map.merge(res, %{
718+
"user_id" => user_id,
719+
"linked_transaction_id" => "de_" <> bounty_transfer["id"]
720+
})
705721

706722
_ ->
707723
res

scripts/v1-progress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
- type: 0
7878
- kind: 0
7979
- visibility: 0
80-
- number: 0
80+
- number: 1
8181
- deleted: 0
8282
- reward_type: 0
8383
- autopay_disabled: 0

0 commit comments

Comments
 (0)