feat: initial commit
Axum/Postgres server with auth, migrations, and Docker setup.
This commit is contained in:
28
migrations/20260812114905_create_user_table.up.sql
Normal file
28
migrations/20260812114905_create_user_table.up.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
password_hash TEXT NOT NULL,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
display_name TEXT NOT NULL,
|
||||
avatar_url TEXT,
|
||||
bio TEXT,
|
||||
email_verified BOOLEAN NOT NULL DEFAULT false,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE TYPE auth_token_kind AS ENUM ('password_reset', 'email_verification', 'refresh_token');
|
||||
|
||||
CREATE TABLE auth_tokens (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
token_hash TEXT NOT NULL,
|
||||
kind auth_token_kind NOT NULL,
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
used_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX auth_tokens_user_id_idx ON auth_tokens(user_id);
|
||||
CREATE INDEX auth_tokens_token_hash_idx ON auth_tokens(token_hash);
|
||||
Reference in New Issue
Block a user