Spaces:
Sleeping
Sleeping
File size: 1,960 Bytes
c1b8488 c057aea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | create extension if not exists pgcrypto;
create table if not exists public.app_users (
id uuid primary key default gen_random_uuid(),
username text not null unique,
password_hash text not null,
created_at timestamptz not null default now()
);
create table if not exists public.app_sessions (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references public.app_users(id) on delete cascade,
token_hash text not null unique,
expires_at timestamptz not null,
created_at timestamptz not null default now()
);
update public.scores
set created_at = now()
where created_at is null;
alter table public.scores
alter column id set default gen_random_uuid();
alter table public.scores
alter column created_at set default now();
alter table public.scores
alter column created_at set not null;
alter table public.scores
alter column user_id drop default;
alter table public.scores
drop constraint if exists scores_user_id_fkey;
alter table public.scores
add constraint scores_user_id_fkey
foreign key (user_id) references public.app_users(id) on delete cascade;
create unique index if not exists scores_user_slug_idx
on public.scores (user_id, slug);
create table if not exists public.score_artifacts (
id uuid primary key default gen_random_uuid(),
score_id uuid not null references public.scores(id) on delete cascade,
user_id uuid not null references public.app_users(id) on delete cascade,
artifact_type text not null,
storage_provider text not null,
object_key text not null,
content_type text not null,
size_bytes bigint not null default 0,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create unique index if not exists score_artifacts_score_user_type_idx
on public.score_artifacts (score_id, user_id, artifact_type);
create index if not exists score_artifacts_user_score_idx
on public.score_artifacts (user_id, score_id);
|