diff --git a/schema/020_usr.sql b/schema/020_usr.sql index 64493d4..56390f0 100644 --- a/schema/020_usr.sql +++ b/schema/020_usr.sql @@ -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(''));