Added user apps and token resources.

This commit is contained in:
2026-10-07 22:45:25 +02:00
parent 1f1f027368
commit 69afcedae1
47 changed files with 1940 additions and 28 deletions
@@ -0,0 +1,4 @@
CREATE TABLE user_apps (
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
user_id UUID NOT NULL CONSTRAINT fk_user_apps_user REFERENCES users (id) ON DELETE CASCADE
);
@@ -0,0 +1,11 @@
CREATE TABLE user_app_secrets (
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
app_id UUID NOT NULL CONSTRAINT fk_user_app_secrets_app REFERENCES user_apps (id) ON DELETE CASCADE,
secret_hash BYTEA NOT NULL CHECK (
octet_length(secret_hash) = 32
),
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX ix_user_app_secrets_app_id ON user_app_secrets (app_id);
@@ -0,0 +1,14 @@
CREATE TABLE tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
app_id UUID NOT NULL CONSTRAINT fk_tokens_app REFERENCES user_apps (id) ON DELETE CASCADE,
access_token_hash BYTEA NOT NULL UNIQUE CHECK (
octet_length(access_token_hash) = 32
),
refresh_token_hash BYTEA NOT NULL UNIQUE CHECK (
octet_length(refresh_token_hash) = 32
),
access_expires_at TIMESTAMPTZ NOT NULL,
refresh_expires_at TIMESTAMPTZ NOT NULL,
revoked_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);