feat: human uid
Some checks failed
migrate-devel / migrate-devel (push) Failing after 7s
migrate-stage / migrate-stage (push) Failing after 8s

This commit is contained in:
Orion Kindel 2023-07-15 22:03:16 -04:00
parent 8b08d9f9c8
commit 4a81f5fbde
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
8 changed files with 4628 additions and 32 deletions

4596
schema/0015_human_uuid.sql Normal file

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,7 @@ $$;
create table public.usr create table public.usr
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, deleted boolean not null default false , deleted boolean not null default false
, tag public.usr_tag not null , tag public.usr_tag not null
, discrim int not null default 0 , discrim int not null default 0

View File

@ -22,7 +22,7 @@ begin
else else
select u.* select u.*
from public.usr u from public.usr u
where u.uid = current_setting('dnim.usr_uid', true) :: uuid where u.uid = human_uuid.huid_of_string(current_setting('dnim.usr_uid', true))
into acting_usr; into acting_usr;
end if; end if;

View File

@ -2,7 +2,7 @@ select create_newtype_text('public.community_tag');
create table public.community create table public.community
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null unique default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, deleted boolean not null default false , deleted boolean not null default false
, tag public.community_tag not null , tag public.community_tag not null
); );

View File

@ -10,7 +10,7 @@ create type public.thread_kind as enum
create table public.thread create table public.thread
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, deleted boolean not null default false , deleted boolean not null default false
, kind public.thread_kind not null , kind public.thread_kind not null
); );
@ -19,11 +19,11 @@ select audit('public', 'thread', array[] :: audited_column[], soft_delete => tru
select immutable('public', 'thread', array['id', 'uid', 'kind']); select immutable('public', 'thread', array['id', 'uid', 'kind']);
create table public.thread_feed create table public.thread_feed
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, deleted boolean not null default false , deleted boolean not null default false
, thread int not null references public.thread(id) , thread int not null references public.thread(id)
-- , community int not null references public.community(id) -- , community int not null references public.community(id)
); );
select audit('public', 'thread_feed', array[] :: audited_column[], soft_delete => true); select audit('public', 'thread_feed', array[] :: audited_column[], soft_delete => true);
@ -41,7 +41,7 @@ create type public.thread_attachment_vote_direction as enum
create table public.thread_attachment create table public.thread_attachment
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, thread int not null references public.thread(id) , thread int not null references public.thread(id)
, kind public.thread_attachment_kind not null , kind public.thread_attachment_kind not null
); );
@ -50,10 +50,10 @@ select audit('public', 'thread_attachment', array[] :: audited_column[], soft_de
select immutable('public', 'thread_attachment', array['id', 'uid', 'thread', 'kind']); select immutable('public', 'thread_attachment', array['id', 'uid', 'thread', 'kind']);
create table public.thread_attachment_emoji create table public.thread_attachment_emoji
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, thread_attachment int not null references public.thread_attachment(id) , thread_attachment int not null references public.thread_attachment(id)
, emoji text not null , emoji text not null
); );
select audit('public', 'thread_attachment_emoji', array[] :: audited_column[], soft_delete => true); select audit('public', 'thread_attachment_emoji', array[] :: audited_column[], soft_delete => true);
@ -61,7 +61,7 @@ select immutable('public', 'thread_attachment_emoji', array['id', 'uid', 'thread
create table public.thread_attachment_vote create table public.thread_attachment_vote
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, thread_attachment int not null references public.thread_attachment(id) , thread_attachment int not null references public.thread_attachment(id)
, direction public.thread_attachment_vote_direction not null , direction public.thread_attachment_vote_direction not null
); );

View File

@ -1,10 +1,10 @@
select create_newtype_text('public.grp_tag'); select create_newtype_text('public.grp_tag');
create table public.grp create table public.grp
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, deleted boolean not null default false , deleted boolean not null default false
, tag public.grp_tag not null unique , tag public.grp_tag not null unique
); );
insert into public.grp (tag) insert into public.grp (tag)

View File

@ -13,8 +13,8 @@ begin
perform public.grp_add_member(to_grp => new_grp, add_usr => new.id); perform public.grp_add_member(to_grp => new_grp, add_usr => new.id);
update public.perm update public.perm
set owner_user = public.usr_root() set owner_user = (public.usr_root()).id
, owner_group = public.grp_admins() , owner_group = (public.grp_admins()).id
where path = '/groups/' || new_grp || '/members' where path = '/groups/' || new_grp || '/members'
or path = '/groups/' || new_grp || '/tag'; or path = '/groups/' || new_grp || '/tag';

View File

@ -2,7 +2,7 @@ create type public.perm_mode as enum ('-', 'r', 'w');
create table public.perm create table public.perm
( id int not null primary key generated always as identity ( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid() , uid human_uuid.huid not null unique default human_uuid.huid()
, owner_user int not null references public.usr(id) , owner_user int not null references public.usr(id)
, owner_group int not null references public.grp(id) , owner_group int not null references public.grp(id)
, owner_user_mode public.perm_mode not null , owner_user_mode public.perm_mode not null
@ -33,15 +33,15 @@ create function do_insert_usr_perm() returns trigger language plpgsql as $$
declare declare
admins int; admins int;
begin begin
admins := public.grp_admins(); admins := (public.grp_admins()).id;
insert into public.perm insert into public.perm
(path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode) (path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode)
values values
('/users/' || NEW.id || '/tag', NEW.id, admins, 'w', 'w', 'r') ('/users/' || human_uuid.huid_to_string(NEW.uid) || '/tag', NEW.id, admins, 'w', 'w', 'r')
, ('/users/' || NEW.id || '/email', NEW.id, admins, 'w', 'w', '-') , ('/users/' || human_uuid.huid_to_string(NEW.uid) || '/email', NEW.id, admins, 'w', 'w', '-')
, ('/users/' || NEW.id || '/deleted', NEW.id, admins, 'w', 'w', '-') , ('/users/' || human_uuid.huid_to_string(NEW.uid) || '/deleted', NEW.id, admins, 'w', 'w', '-')
, ('/users/' || NEW.id || '/password', NEW.id, admins, 'w', 'w', '-') , ('/users/' || human_uuid.huid_to_string(NEW.uid) || '/password', NEW.id, admins, 'w', 'w', '-')
; ;
return new; return new;
@ -57,8 +57,8 @@ begin
insert into public.perm insert into public.perm
(path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode) (path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode)
values values
('/groups/' || NEW.id || '/members', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-') ('/groups/' || human_uuid.huid_to_string(NEW.uid) || '/members', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-')
, ('/groups/' || NEW.id || '/tag', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r') , ('/groups/' || human_uuid.huid_to_string(NEW.uid) || '/tag', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r')
; ;
return new; return new;
@ -77,9 +77,9 @@ begin
insert into public.perm insert into public.perm
(path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode) (path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode)
values values
('/communities/' || NEW.id || '/posts', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r') ('/communities/' || human_uuid.huid_to_string(NEW.uid) || '/posts', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r')
, ('/communities/' || NEW.id || '/tag', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r') , ('/communities/' || human_uuid.huid_to_string(NEW.uid) || '/tag', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r')
, ('/communities/' || NEW.id || '/deleted', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-') , ('/communities/' || human_uuid.huid_to_string(NEW.uid) || '/deleted', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-')
; ;
return new; return new;