mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Record per-user Attempt history (#39)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
defmodule Chesstrainer.Repo.Migrations.CreateAttempts do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:attempts, primary_key: false) do
|
||||
add :id, :binary_id, primary_key: true
|
||||
add :user_id, references(:users, type: :binary_id, on_delete: :delete_all), null: false
|
||||
|
||||
add :endgame_id, references(:endgames, type: :binary_id, on_delete: :delete_all),
|
||||
null: false
|
||||
|
||||
add :outcome, :string, null: false
|
||||
add :rated_at, :utc_datetime
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
# Independent foreign-key indexes so cascade deletes stay cheap.
|
||||
create index(:attempts, [:user_id])
|
||||
create index(:attempts, [:endgame_id])
|
||||
|
||||
# Rating-window lookup: the latest rated attempt for a user/endgame pair.
|
||||
create index(:attempts, [:user_id, :endgame_id, :rated_at], where: "rated_at IS NOT NULL")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user