feat: add tag discriminator

This commit is contained in:
Orion Kindel 2023-07-07 16:20:07 -05:00
parent be07aca4c5
commit 96937dfa25
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -33,10 +33,19 @@ create table public.usr
, uid uuid not null default gen_random_uuid()
, deleted boolean not null default false
, tag public.usr_tag not null
, discrim int not null
, password public.hashed_text not null
, email public.email not null unique
, unique (tag, discrim)
);
create function public.usr_tag_count(tag public.usr_tag) returns int language sql stable as $$
select count(*) from public.usr u where u.tag = tag;
$$;
alter table public.usr
alter column discrim set default public.usr_tag_count(tag);
insert into public.usr (tag, password, email)
values (usr_tag_of_string('system'), hashed_text_of_string(''), email_of_string(''));