mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
- Scaffold password auth (email or username) with phx.gen.auth; no magic links - Add role (member/moderator/admin/super_admin) and plan (free/premium) enums - Gate /admin behind admin-or-above via plug + on_mount; hide the nav link - Add mix accounts.promote for CLI role changes - Disable email confirmation by confirming accounts at registration Closes #3
37 lines
1.2 KiB
Elixir
37 lines
1.2 KiB
Elixir
defmodule Chesstrainer.Repo.Migrations.CreateUsersAuthTables do
|
|
use Ecto.Migration
|
|
|
|
def change do
|
|
execute "CREATE EXTENSION IF NOT EXISTS citext", ""
|
|
|
|
create table(:users, primary_key: false) do
|
|
add :id, :binary_id, primary_key: true
|
|
add :email, :citext, null: false
|
|
add :username, :citext, null: false
|
|
add :hashed_password, :string
|
|
add :role, :string, null: false, default: "member"
|
|
add :plan, :string, null: false, default: "free"
|
|
add :confirmed_at, :utc_datetime
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
create unique_index(:users, [:email])
|
|
create unique_index(:users, [:username])
|
|
|
|
create table(:users_tokens, 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 :token, :binary, null: false
|
|
add :context, :string, null: false
|
|
add :sent_to, :string
|
|
add :authenticated_at, :utc_datetime
|
|
|
|
timestamps(type: :utc_datetime, updated_at: false)
|
|
end
|
|
|
|
create index(:users_tokens, [:user_id])
|
|
create unique_index(:users_tokens, [:context, :token])
|
|
end
|
|
end
|