2023-06-11 16:26:39 +00:00
|
|
|
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()
|
|
|
|
, deleted boolean not null default false
|
|
|
|
, tag public.community_tag not null
|
|
|
|
);
|
|
|
|
|
|
|
|
select audit( 'public'
|
|
|
|
, 'community'
|
|
|
|
, array[ row('tag', 'public.community_tag')
|
|
|
|
] :: audited_column[]
|
|
|
|
, soft_delete => true
|
|
|
|
);
|
|
|
|
|
|
|
|
select immutable( 'public'
|
|
|
|
, 'community'
|
|
|
|
, array[ 'id'
|
|
|
|
, 'uid'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
create table public.community_nonmember_scope
|
|
|
|
( id int not null primary key generated always as identity
|
|
|
|
, uid uuid not null unique default gen_random_uuid()
|
|
|
|
, community int not null references public.community (id)
|
|
|
|
, scope public.authz_scope not null
|
|
|
|
, unique (community, scope)
|
|
|
|
);
|
|
|
|
|
|
|
|
select audit( 'public'
|
|
|
|
, 'community_nonmember_scope'
|
|
|
|
, array[ row('community', 'int')
|
|
|
|
, row('scope', 'public.authz_scope')
|
|
|
|
] :: audited_column[]
|
|
|
|
, soft_delete => false
|
|
|
|
);
|
|
|
|
|
|
|
|
select immutable( 'public'
|
|
|
|
, 'community_nonmember_scope'
|
|
|
|
, array[ 'id'
|
|
|
|
, 'uid'
|
|
|
|
, 'community'
|
|
|
|
, 'scope'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
create table public.community_member_role
|
|
|
|
( id int not null primary key generated always as identity
|
|
|
|
, uid uuid not null unique default gen_random_uuid()
|
2023-06-11 17:01:51 +00:00
|
|
|
, community int not null references public.community (id)
|
2023-06-11 16:26:39 +00:00
|
|
|
, title text not null
|
|
|
|
, description text not null
|
|
|
|
);
|
|
|
|
|
|
|
|
select audit( 'public'
|
|
|
|
, 'community_member_role'
|
|
|
|
, array[ row('title', 'text')
|
|
|
|
, row('description', 'text')
|
|
|
|
] :: audited_column[]
|
|
|
|
, soft_delete => false
|
|
|
|
);
|
|
|
|
|
|
|
|
select immutable( 'public'
|
|
|
|
, 'community_member_role'
|
|
|
|
, array[ 'id'
|
|
|
|
, 'uid'
|
2023-06-11 17:01:51 +00:00
|
|
|
, 'community'
|
2023-06-11 16:26:39 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
create table public.community_member_role_scope
|
|
|
|
( id int not null primary key generated always as identity
|
|
|
|
, uid uuid not null unique default gen_random_uuid()
|
|
|
|
, role_ int not null references public.community_member_role (id)
|
|
|
|
, scope public.authz_scope not null
|
|
|
|
, unique (scope, role_)
|
|
|
|
);
|
|
|
|
|
|
|
|
select audit( 'public'
|
|
|
|
, 'community_member_role_scope'
|
|
|
|
, array[ row('role_', 'int')
|
|
|
|
, row('scope', 'public.authz_scope')
|
|
|
|
] :: audited_column[]
|
|
|
|
, soft_delete => false
|
|
|
|
);
|
|
|
|
|
|
|
|
select immutable( 'public'
|
|
|
|
, 'community_member_role_scope'
|
|
|
|
, array[ 'id'
|
|
|
|
, 'uid'
|
|
|
|
, 'role_'
|
|
|
|
, 'scope'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
create table public.community_member
|
2023-06-11 17:01:51 +00:00
|
|
|
( id int not null primary key generated always as identity
|
|
|
|
, uid uuid not null unique default gen_random_uuid()
|
|
|
|
, usr int not null references public.usr (id)
|
|
|
|
, community int not null references public.community (id)
|
|
|
|
, role_ int not null references public.community_member_role (id)
|
2023-06-11 16:26:39 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
select audit( 'public'
|
|
|
|
, 'community_member'
|
|
|
|
, array[ row('usr', 'int')
|
|
|
|
, row('role_', 'int')
|
|
|
|
] :: audited_column[]
|
|
|
|
, soft_delete => false
|
|
|
|
);
|
|
|
|
|
|
|
|
select immutable( 'public'
|
|
|
|
, 'community_member'
|
|
|
|
, array[ 'id'
|
|
|
|
, 'uid'
|
|
|
|
, 'usr'
|
|
|
|
]
|
|
|
|
);
|