Huge refactor for backend and client

This is barely functionnal, but at least it can display some data without crashing
Most other functionnalities other than displaying events are broken, and so are the relative date operations, they need to be fixed asap
This commit is contained in:
Alexis
2024-05-16 22:58:19 +02:00
parent 49e523485b
commit 67f5a270af
28 changed files with 247 additions and 303 deletions

View File

@@ -47,33 +47,41 @@ comment on table public.worlds is 'Worlds belonging to a single user ; a game ma
-- World Calendars
create table public.world_calendars (
id bigint generated by default as identity primary key,
months text array,
days_per_year int 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.';
-- Calendar Months
create table public.calendar_months (
id bigint generated by default as identity primary key,
name text not null,
days int not null,
position int not null,
calendar_id bigint references public.world_calendars on delete cascade not null
);
comment on table public.calendar_months is 'A calendar month.';
-- Event categories
create table public.events_category (
create table public.calendar_events_category (
id bigint generated by default as identity primary key,
name text not null,
unique (name)
);
comment on table public.events_category is 'Categories describing events';
comment on table public.calendar_events_category is 'Categories describing events';
-- Events
create table public.events (
create table public.calendar_events (
id bigint generated by default as identity primary key,
title text not null,
description text,
start_date json not null,
end_date json,
category bigint references public.events_category on delete cascade,
category bigint references public.calendar_events_category on delete cascade,
hidden boolean,
wiki text,
calendar_id bigint references public.world_calendars on delete cascade not null
);
comment on table public.events is 'Events linked to a world';
comment on table public.calendar_events is 'Events linked to a world';
-- Character categories
create table public.characters_category (
@@ -121,11 +129,12 @@ 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.world_calendars enable row level security;
alter table public.events_category enable row level security;
alter table public.characters_category enable row level security;
alter table public.characters enable row level security;
alter table public.events enable row level security;
alter table public.world_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;
-- User policies
create policy "Allow logged-in read access" on public.users for select using ( auth.role() = 'authenticated' );
@@ -158,23 +167,43 @@ create policy "Allow individual update access for GMs" on public.world_calendars
)
);
-- 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
)
);
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
)
);
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
)
);
-- Event policies
create policy "Allow individual read access for GMs" on public.events for select using (
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 = events.calendar_id
where world_calendars.id = calendar_events.calendar_id
)
);
create policy "Allow individual insert access for GMs" on public.events for insert with check (
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 = events.calendar_id
where world_calendars.id = calendar_events.calendar_id
)
);
create policy "Allow individual update access for GMs" on public.events for update with check (
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 = events.calendar_id
where world_calendars.id = calendar_events.calendar_id
)
);
@@ -198,6 +227,10 @@ 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' );
-- Send "previous data" on change
alter table public.users replica identity full;