Added secondary categories to events / characters
This commit is contained in:
@@ -45,11 +45,12 @@ create table public.worlds (
|
||||
comment on table public.worlds is 'Worlds belonging to a single user ; a game master.';
|
||||
|
||||
-- World Calendars
|
||||
create table public.world_calendars (
|
||||
create table public.calendars (
|
||||
id bigint generated by default as identity primary key,
|
||||
name text not null,
|
||||
world_id bigint references public.worlds on delete cascade not null
|
||||
);
|
||||
comment on table public.world_calendars is 'Calendar settings and configuration attached to a single world.';
|
||||
comment on table public.calendars is 'Calendar settings and configuration attached to a single world.';
|
||||
|
||||
-- Calendar Months
|
||||
create table public.calendar_months (
|
||||
@@ -57,17 +58,17 @@ create table public.calendar_months (
|
||||
name text not null,
|
||||
days int not null,
|
||||
position int not null,
|
||||
calendar_id bigint references public.world_calendars on delete cascade not null
|
||||
calendar_id bigint references public.calendars on delete cascade not null
|
||||
);
|
||||
comment on table public.calendar_months is 'A calendar month.';
|
||||
|
||||
-- Event categories
|
||||
create table public.calendar_events_category (
|
||||
create table public.calendar_event_categories (
|
||||
id bigint generated by default as identity primary key,
|
||||
name text not null,
|
||||
unique (name)
|
||||
);
|
||||
comment on table public.calendar_events_category is 'Categories describing events';
|
||||
comment on table public.calendar_event_categories is 'Categories describing events.';
|
||||
|
||||
-- Events
|
||||
create table public.calendar_events (
|
||||
@@ -76,36 +77,52 @@ create table public.calendar_events (
|
||||
description text,
|
||||
start_date json not null,
|
||||
end_date json,
|
||||
category bigint references public.calendar_events_category on delete cascade,
|
||||
category bigint references public.calendar_event_categories on delete cascade,
|
||||
hidden boolean,
|
||||
wiki text,
|
||||
calendar_id bigint references public.world_calendars on delete cascade not null
|
||||
calendar_id bigint references public.calendars on delete cascade not null
|
||||
);
|
||||
comment on table public.calendar_events is 'Events linked to a world';
|
||||
|
||||
-- Link table for events - categories
|
||||
create table public.calendar_event_categories_links (
|
||||
calendar_event_id bigint references public.calendar_events on delete cascade,
|
||||
calendar_event_category_id bigint references public.calendar_event_categories on delete cascade,
|
||||
primary key (calendar_event_id, calendar_event_category_id)
|
||||
);
|
||||
comment on table public.calendar_event_categories_links is 'Link tables for multiple event categories.';
|
||||
|
||||
-- Character categories
|
||||
create table public.characters_category (
|
||||
create table public.character_categories (
|
||||
id bigint generated by default as identity primary key,
|
||||
name text not null,
|
||||
unique (name)
|
||||
);
|
||||
comment on table public.characters_category is 'Categories describing characters';
|
||||
comment on table public.character_categories is 'Categories describing characters';
|
||||
|
||||
-- Characters
|
||||
create table public.characters (
|
||||
id bigint generated by default as identity primary key,
|
||||
name text not null,
|
||||
description text,
|
||||
birth json not null,
|
||||
death json,
|
||||
category bigint references public.characters_category on delete cascade,
|
||||
id bigint generated by default as identity primary key,
|
||||
name text not null,
|
||||
description text,
|
||||
birth json not null,
|
||||
death json,
|
||||
category bigint references public.character_categories on delete cascade,
|
||||
hidden_birth boolean,
|
||||
hidden_death boolean,
|
||||
wiki text,
|
||||
world_id bigint references public.worlds on delete cascade not null
|
||||
wiki text,
|
||||
world_id bigint references public.worlds on delete cascade not null
|
||||
);
|
||||
comment on table public.characters is 'Characters linked to a world';
|
||||
|
||||
-- Link table for events - categories
|
||||
create table public.character_categories_links (
|
||||
character_id bigint references public.characters on delete cascade,
|
||||
character_category_id bigint references public.character_categories on delete cascade,
|
||||
primary key (character_id, character_category_id)
|
||||
);
|
||||
comment on table public.character_categories_links is 'Link tables for multiple character categories.';
|
||||
|
||||
-- authorize with role-based access control (RBAC)
|
||||
create function public.authorize(
|
||||
requested_permission app_permission
|
||||
@@ -129,12 +146,14 @@ alter table public.users enable row level security;
|
||||
alter table public.user_roles enable row level security;
|
||||
alter table public.role_permissions enable row level security;
|
||||
alter table public.worlds enable row level security;
|
||||
alter table public.characters_category enable row level security;
|
||||
alter table public.character_categories enable row level security;
|
||||
alter table public.character_categories_links enable row level security;
|
||||
alter table public.characters enable row level security;
|
||||
alter table public.world_calendars enable row level security;
|
||||
alter table public.calendars enable row level security;
|
||||
alter table public.calendar_months enable row level security;
|
||||
alter table public.calendar_events enable row level security;
|
||||
alter table public.calendar_events_category enable row level security;
|
||||
alter table public.calendar_event_categories enable row level security;
|
||||
alter table public.calendar_event_categories_links enable row level security;
|
||||
|
||||
-- User policies
|
||||
create policy "Allow logged-in read access" on public.users for select using ( auth.role() = 'authenticated' );
|
||||
@@ -148,62 +167,62 @@ create policy "Allow individual insert access for GMs" on public.worlds for inse
|
||||
create policy "Allow individual update access for GMs" on public.worlds for update using ( auth.uid() = gm_id );
|
||||
|
||||
-- Calendar policies
|
||||
create policy "Allow individual read access for GMs" on public.world_calendars for select using (
|
||||
create policy "Allow individual read access for GMs" on public.calendars for select using (
|
||||
exists (
|
||||
select 1 from worlds
|
||||
where worlds.id = world_calendars.world_id
|
||||
where worlds.id = calendars.world_id
|
||||
)
|
||||
);
|
||||
create policy "Allow individual insert access for GMs" on public.world_calendars for insert with check (
|
||||
create policy "Allow individual insert access for GMs" on public.calendars for insert with check (
|
||||
exists (
|
||||
select 1 from worlds
|
||||
where worlds.id = world_calendars.world_id
|
||||
where worlds.id = calendars.world_id
|
||||
)
|
||||
);
|
||||
create policy "Allow individual update access for GMs" on public.world_calendars for update with check (
|
||||
create policy "Allow individual update access for GMs" on public.calendars for update with check (
|
||||
exists (
|
||||
select 1 from worlds
|
||||
where worlds.id = world_calendars.world_id
|
||||
where worlds.id = calendars.world_id
|
||||
)
|
||||
);
|
||||
|
||||
-- Month policies
|
||||
create policy "Allow individual read access for GMs" on public.calendar_months for select using (
|
||||
exists (
|
||||
select 1 from world_calendars
|
||||
where world_calendars.id = calendar_months.calendar_id
|
||||
select 1 from calendars
|
||||
where calendars.id = calendar_months.calendar_id
|
||||
)
|
||||
);
|
||||
create policy "Allow individual insert access for GMs" on public.calendar_months for insert with check (
|
||||
exists (
|
||||
select 1 from world_calendars
|
||||
where world_calendars.id = calendar_months.calendar_id
|
||||
select 1 from calendars
|
||||
where calendars.id = calendar_months.calendar_id
|
||||
)
|
||||
);
|
||||
create policy "Allow individual update access for GMs" on public.calendar_months for update with check (
|
||||
exists (
|
||||
select 1 from world_calendars
|
||||
where world_calendars.id = calendar_months.calendar_id
|
||||
select 1 from calendars
|
||||
where calendars.id = calendar_months.calendar_id
|
||||
)
|
||||
);
|
||||
|
||||
-- Event policies
|
||||
create policy "Allow individual read access for GMs" on public.calendar_events for select using (
|
||||
exists (
|
||||
select 1 from world_calendars
|
||||
where world_calendars.id = calendar_events.calendar_id
|
||||
select 1 from calendars
|
||||
where calendars.id = calendar_events.calendar_id
|
||||
)
|
||||
);
|
||||
create policy "Allow individual insert access for GMs" on public.calendar_events for insert with check (
|
||||
exists (
|
||||
select 1 from world_calendars
|
||||
where world_calendars.id = calendar_events.calendar_id
|
||||
select 1 from calendars
|
||||
where calendars.id = calendar_events.calendar_id
|
||||
)
|
||||
);
|
||||
create policy "Allow individual update access for GMs" on public.calendar_events for update with check (
|
||||
exists (
|
||||
select 1 from world_calendars
|
||||
where world_calendars.id = calendar_events.calendar_id
|
||||
select 1 from calendars
|
||||
where calendars.id = calendar_events.calendar_id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -228,8 +247,11 @@ create policy "Allow individual update access for GMs" on public.characters for
|
||||
);
|
||||
|
||||
-- Categories are public to view but not to insert
|
||||
create policy "Allow logged-in read access" on public.calendar_events_category for select using ( auth.role() = 'authenticated' );
|
||||
create policy "Allow logged-in read access" on public.characters_category for select using ( auth.role() = 'authenticated' );
|
||||
-- Needs to be refactored maybe, if in the future we want a default set AND user defined ones
|
||||
create policy "Allow logged-in read access" on public.calendar_event_categories for select using ( auth.role() = 'authenticated' );
|
||||
create policy "Allow logged-in read access" on public.calendar_event_categories_links for select using ( auth.role() = 'authenticated' );
|
||||
create policy "Allow logged-in read access" on public.character_categories for select using ( auth.role() = 'authenticated' );
|
||||
create policy "Allow logged-in read access" on public.character_categories_links for select using ( auth.role() = 'authenticated' );
|
||||
|
||||
-- Send "previous data" on change
|
||||
alter table public.users replica identity full;
|
||||
|
||||
Reference in New Issue
Block a user