update db: make puuid unique, add status column

This commit is contained in:
2024-05-05 02:33:00 +02:00
parent dde4e3bf90
commit 367d751af0
4 changed files with 20 additions and 3 deletions
@@ -18,9 +18,12 @@ defmodule LolAnalytics.Player.PlayerRepo do
LoLAnalytics.Repo.one(query)
end
def insert_player(puuid) do
@spec insert_player(String.t(), keyword()) :: %PlayerSchema{}
def insert_player(puuid, attrs \\ %{}) do
attrs = Map.merge(%{puuid: puuid, region: "EUW", status: "queued"}, attrs)
%PlayerSchema{}
|> PlayerSchema.changeset(%{puuid: puuid, region: "EUW"})
|> PlayerSchema.changeset(attrs)
|> LoLAnalytics.Repo.insert()
end
@@ -18,5 +18,6 @@ defmodule LolAnalytics.Player.PlayerSchema do
player
|> cast(params, [:puuid, :region, :last_processed_at])
|> validate_required([:puuid, :region, :last_processed_at])
|> unique_constraint(:puuid)
end
end