This commit is contained in:
Giovanni Rezcjikov
2026-03-09 18:09:02 +03:00
parent be36c6f0c4
commit f188150c9f
25 changed files with 694 additions and 53 deletions
+29 -1
View File
@@ -85,4 +85,32 @@ WHERE revoked_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_user_consents_user_id ON public.user_consents(user_id);
CREATE INDEX IF NOT EXISTS idx_user_consents_client_id ON public.user_consents(client_id);
CREATE INDEX IF NOT EXISTS idx_user_consents_revoked ON public.user_consents(revoked_at) WHERE revoked_at IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_user_consents_revoked ON public.user_consents(revoked_at) WHERE revoked_at IS NOT NULL;
CREATE TABLE IF NOT EXISTS public.positions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
code text NOT NULL UNIQUE,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS public.position_translations (
position_id uuid NOT NULL REFERENCES public.positions(id) ON DELETE CASCADE,
locale text NOT NULL,
name text NOT NULL,
description text,
PRIMARY KEY (position_id, locale)
);
CREATE TABLE IF NOT EXISTS public.user_positions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
position_id uuid NOT NULL REFERENCES public.positions(id) ON DELETE CASCADE,
valid_from timestamptz NOT NULL DEFAULT now(),
valid_to timestamptz,
CONSTRAINT user_positions_unique_active UNIQUE (user_id, position_id)
DEFERRABLE INITIALLY IMMEDIATE
);
CREATE INDEX IF NOT EXISTS idx_user_positions_user_id ON public.user_positions(user_id);
CREATE INDEX IF NOT EXISTS idx_user_positions_position_id ON public.user_positions(position_id);