- Full auth system with email/password (using phx.gen.auth) - Login, registration, password reset - Session management with remember-me functionality - Magic link login support 2. Organization Management - Multi-tenant organization system - Organizations schema with unique slugs - Automatic organization creation when users register - Organization switcher UI at /orgs 3. Membership System - Users can belong to multiple organizations - 4 permission levels: Owner, Admin, Member, Viewer - Complete permission matrix implemented - Join/leave organizations 4. Invitation System - Email-based invitations with secure tokens - 7-day expiration on invites - Track who invited and who accepted 5. Authorization - Full policy system (Organizations.Policy) - can?(membership, :action, :resource) helper - Enforced via plugs in router 6. LiveView Pages - /orgs - List all your organizations - /orgs/new - Create new organization - /orgs/:slug - Organization dashboard (placeholder) 7. Database Schema - users table - organizations table - organization_memberships table - organization_invitations table - All migrations run successfully
32 lines
978 B
Elixir
32 lines
978 B
Elixir
defmodule Towerops.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 :hashed_password, :string
|
|
add :confirmed_at, :utc_datetime
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
create unique_index(:users, [:email])
|
|
|
|
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
|