feat: human uid
This commit is contained in:
parent
8b08d9f9c8
commit
4a81f5fbde
4596
schema/0015_human_uuid.sql
Normal file
4596
schema/0015_human_uuid.sql
Normal file
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,7 @@ $$;
|
||||
|
||||
create table public.usr
|
||||
( 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
|
||||
, tag public.usr_tag not null
|
||||
, discrim int not null default 0
|
||||
|
@ -22,7 +22,7 @@ begin
|
||||
else
|
||||
select 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;
|
||||
end if;
|
||||
|
||||
|
@ -2,7 +2,7 @@ select create_newtype_text('public.community_tag');
|
||||
|
||||
create table public.community
|
||||
( 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
|
||||
, tag public.community_tag not null
|
||||
);
|
||||
|
@ -10,7 +10,7 @@ create type public.thread_kind as enum
|
||||
|
||||
create table public.thread
|
||||
( 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
|
||||
, 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']);
|
||||
|
||||
create table public.thread_feed
|
||||
( id int not null primary key generated always as identity
|
||||
, uid uuid not null default gen_random_uuid()
|
||||
, deleted boolean not null default false
|
||||
, thread int not null references public.thread(id)
|
||||
-- , community int not null references public.community(id)
|
||||
( id int not null primary key generated always as identity
|
||||
, uid human_uuid.huid not null unique default human_uuid.huid()
|
||||
, deleted boolean not null default false
|
||||
, thread int not null references public.thread(id)
|
||||
-- , community int not null references public.community(id)
|
||||
);
|
||||
|
||||
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
|
||||
( 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)
|
||||
, 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']);
|
||||
|
||||
create table public.thread_attachment_emoji
|
||||
( id int not null primary key generated always as identity
|
||||
, uid uuid not null default gen_random_uuid()
|
||||
, thread_attachment int not null references public.thread_attachment(id)
|
||||
, emoji text not null
|
||||
( id int not null primary key generated always as identity
|
||||
, uid human_uuid.huid not null unique default human_uuid.huid()
|
||||
, thread_attachment int not null references public.thread_attachment(id)
|
||||
, emoji text not null
|
||||
);
|
||||
|
||||
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
|
||||
( 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)
|
||||
, direction public.thread_attachment_vote_direction not null
|
||||
);
|
||||
|
@ -1,10 +1,10 @@
|
||||
select create_newtype_text('public.grp_tag');
|
||||
|
||||
create table public.grp
|
||||
( id int not null primary key generated always as identity
|
||||
, uid uuid not null default gen_random_uuid()
|
||||
, deleted boolean not null default false
|
||||
, tag public.grp_tag not null unique
|
||||
( id int not null primary key generated always as identity
|
||||
, uid human_uuid.huid not null unique default human_uuid.huid()
|
||||
, deleted boolean not null default false
|
||||
, tag public.grp_tag not null unique
|
||||
);
|
||||
|
||||
insert into public.grp (tag)
|
||||
|
@ -13,8 +13,8 @@ begin
|
||||
perform public.grp_add_member(to_grp => new_grp, add_usr => new.id);
|
||||
|
||||
update public.perm
|
||||
set owner_user = public.usr_root()
|
||||
, owner_group = public.grp_admins()
|
||||
set owner_user = (public.usr_root()).id
|
||||
, owner_group = (public.grp_admins()).id
|
||||
where path = '/groups/' || new_grp || '/members'
|
||||
or path = '/groups/' || new_grp || '/tag';
|
||||
|
||||
|
@ -2,7 +2,7 @@ create type public.perm_mode as enum ('-', 'r', 'w');
|
||||
|
||||
create table public.perm
|
||||
( 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_group int not null references public.grp(id)
|
||||
, owner_user_mode public.perm_mode not null
|
||||
@ -33,15 +33,15 @@ create function do_insert_usr_perm() returns trigger language plpgsql as $$
|
||||
declare
|
||||
admins int;
|
||||
begin
|
||||
admins := public.grp_admins();
|
||||
admins := (public.grp_admins()).id;
|
||||
|
||||
insert into public.perm
|
||||
(path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode)
|
||||
values
|
||||
('/users/' || NEW.id || '/tag', NEW.id, admins, 'w', 'w', 'r')
|
||||
, ('/users/' || NEW.id || '/email', NEW.id, admins, 'w', 'w', '-')
|
||||
, ('/users/' || NEW.id || '/deleted', NEW.id, admins, 'w', 'w', '-')
|
||||
, ('/users/' || NEW.id || '/password', NEW.id, admins, 'w', 'w', '-')
|
||||
('/users/' || human_uuid.huid_to_string(NEW.uid) || '/tag', NEW.id, admins, 'w', 'w', 'r')
|
||||
, ('/users/' || human_uuid.huid_to_string(NEW.uid) || '/email', NEW.id, admins, 'w', 'w', '-')
|
||||
, ('/users/' || human_uuid.huid_to_string(NEW.uid) || '/deleted', NEW.id, admins, 'w', 'w', '-')
|
||||
, ('/users/' || human_uuid.huid_to_string(NEW.uid) || '/password', NEW.id, admins, 'w', 'w', '-')
|
||||
;
|
||||
|
||||
return new;
|
||||
@ -57,8 +57,8 @@ begin
|
||||
insert into public.perm
|
||||
(path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode)
|
||||
values
|
||||
('/groups/' || NEW.id || '/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) || '/members', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-')
|
||||
, ('/groups/' || human_uuid.huid_to_string(NEW.uid) || '/tag', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r')
|
||||
;
|
||||
|
||||
return new;
|
||||
@ -77,9 +77,9 @@ begin
|
||||
insert into public.perm
|
||||
(path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode)
|
||||
values
|
||||
('/communities/' || NEW.id || '/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/' || NEW.id || '/deleted', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-')
|
||||
('/communities/' || human_uuid.huid_to_string(NEW.uid) || '/posts', (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/' || human_uuid.huid_to_string(NEW.uid) || '/deleted', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-')
|
||||
;
|
||||
|
||||
return new;
|
||||
|
Loading…
Reference in New Issue
Block a user