update db: make puuid unique, add status column

This commit is contained in:
Álvaro 2024-05-05 02:33:00 +02:00
parent dde4e3bf90
commit 367d751af0
4 changed files with 20 additions and 3 deletions

View File

@ -18,9 +18,12 @@ defmodule LolAnalytics.Player.PlayerRepo do
LoLAnalytics.Repo.one(query) LoLAnalytics.Repo.one(query)
end 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{}
|> PlayerSchema.changeset(%{puuid: puuid, region: "EUW"}) |> PlayerSchema.changeset(attrs)
|> LoLAnalytics.Repo.insert() |> LoLAnalytics.Repo.insert()
end end

View File

@ -18,5 +18,6 @@ defmodule LolAnalytics.Player.PlayerSchema do
player player
|> cast(params, [:puuid, :region, :last_processed_at]) |> cast(params, [:puuid, :region, :last_processed_at])
|> validate_required([:puuid, :region, :last_processed_at]) |> validate_required([:puuid, :region, :last_processed_at])
|> unique_constraint(:puuid)
end end
end end

View File

@ -3,7 +3,7 @@ defmodule LoLAnalytics.Repo.Migrations.Player do
def change do def change do
create table("player") do create table("player") do
add :puuid, :string add :puuid, :string, primary_key: true
add :region, :string add :region, :string
add :last_processed_at, :utc_datetime add :last_processed_at, :utc_datetime
timestamps() timestamps()

View File

@ -0,0 +1,13 @@
defmodule LoLAnalytics.Repo.Migrations.MatchAndPlayerStatus do
use Ecto.Migration
def change do
alter table("match") do
add :status, :string, default: "processed"
end
alter table("player") do
add :status, :string, default: "processed"
end
end
end