customer/migrations/0001_accounts.sql
Peppa 4acc7f5ea6
All checks were successful
peppa/lint lint: success за 0с
peppa/typecheck typecheck: success за 1с
peppa/test test: success за 14с
peppa/build build: success за 1с
ci / checks (pull_request) Successful in 25s
deploy / deploy (pull_request) Successful in 3s
CLT-2: Postgres, миграции, учётные записи, сессии, CSRF, rate-limit, удаление аккаунта
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 13:24:05 +05:00

28 lines
931 B
SQL

CREATE TABLE organizations (
id uuid PRIMARY KEY,
name text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE users (
id uuid PRIMARY KEY,
email text NOT NULL,
password_hash text NOT NULL,
role text NOT NULL CHECK (role IN ('buyer', 'org_admin', 'operator')),
org_id uuid REFERENCES organizations (id) ON DELETE RESTRICT,
created_at timestamptz NOT NULL DEFAULT now(),
CHECK ((role = 'buyer') = (org_id IS NULL))
);
CREATE UNIQUE INDEX users_email_lower_idx ON users (lower(email));
CREATE INDEX users_org_id_idx ON users (org_id);
CREATE TABLE sessions (
token_hash bytea PRIMARY KEY,
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
csrf_token text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
expires_at timestamptz NOT NULL
);
CREATE INDEX sessions_user_id_idx ON sessions (user_id);
CREATE INDEX sessions_expires_at_idx ON sessions (expires_at);