Skip to content

Commit 62975d3

Browse files
committed
fix more issues
1 parent 37e08b0 commit 62975d3

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,6 @@ defmodule DatabaseMigration do
244244
end
245245

246246
defp transform({"GithubUser", User}, row, _db) do
247-
if row["type"] != "User" do
248-
Logger.warning("GithubUser is not a User: #{inspect(row["login"])}")
249-
end
250-
251247
if nullish?(row["user_id"]) do
252248
%{
253249
"id" => row["id"],
@@ -335,15 +331,18 @@ defmodule DatabaseMigration do
335331

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

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-
}
334+
if row["type"] != "tip" do
335+
%{
336+
"id" => row["id"],
337+
"amount" => amount,
338+
"ticket_id" => row["task_id"],
339+
"owner_id" => row["org_id"],
340+
"creator_id" => row["poster_id"],
341+
"inserted_at" => row["created_at"],
342+
"updated_at" => row["updated_at"],
343+
"number" => row["number"]
344+
}
345+
end
347346
end
348347

349348
defp transform({"Bounty", CommandResponse}, row, _db) do
@@ -547,20 +546,23 @@ defmodule DatabaseMigration do
547546
bounty_transfer: row,
548547
bounty: bounty,
549548
claim: claim,
550-
user_id: org["id"]
549+
org: org,
550+
user_id: user_id
551551
}),
552552
maybe_create_transaction("credit", %{
553553
bounty_charge: bounty_charge,
554554
bounty_transfer: row,
555555
bounty: bounty,
556556
claim: claim,
557+
org: org,
557558
user_id: user_id
558559
}),
559560
maybe_create_transaction("transfer", %{
560561
bounty_charge: bounty_charge,
561562
bounty_transfer: row,
562563
bounty: bounty,
563564
claim: claim,
565+
org: org,
564566
user_id: user_id
565567
})
566568
],
@@ -647,6 +649,7 @@ defmodule DatabaseMigration do
647649
bounty_transfer: bounty_transfer,
648650
bounty: bounty,
649651
claim: claim,
652+
org: org,
650653
user_id: user_id
651654
}) do
652655
amount = Money.from_integer(String.to_integer(bounty_transfer["amount"]), bounty_transfer["currency"])
@@ -671,7 +674,7 @@ defmodule DatabaseMigration do
671674
"succeeded_at" => nil,
672675
"reversed_at" => nil,
673676
"group_id" => bounty_charge["id"],
674-
"user_id" => user_id,
677+
"user_id" => nil,
675678
"contract_id" => nil,
676679
"original_contract_id" => nil,
677680
"timesheet_id" => nil,
@@ -695,13 +698,22 @@ defmodule DatabaseMigration do
695698
res =
696699
case type do
697700
"transfer" ->
698-
Map.put(res, "provider_id", bounty_transfer["transfer_id"])
701+
Map.merge(res, %{
702+
"user_id" => user_id,
703+
"provider_id" => bounty_transfer["transfer_id"]
704+
})
699705

700706
"debit" ->
701-
Map.put(res, "linked_transaction_id", "cr_" <> bounty_transfer["id"])
707+
Map.merge(res, %{
708+
"user_id" => org["id"],
709+
"linked_transaction_id" => "cr_" <> bounty_transfer["id"]
710+
})
702711

703712
"credit" ->
704-
Map.put(res, "linked_transaction_id", "de_" <> bounty_transfer["id"])
713+
Map.merge(res, %{
714+
"user_id" => user_id,
715+
"linked_transaction_id" => "de_" <> bounty_transfer["id"]
716+
})
705717

706718
_ ->
707719
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)