Changed categories to be linked to calendars and worlds
This commit is contained in:
@@ -14,40 +14,40 @@ create type public.calendar_state as enum ('published', 'draft', 'archived');
|
|||||||
-- DATA STRUCTURES
|
-- DATA STRUCTURES
|
||||||
-- Users
|
-- Users
|
||||||
create table public.users (
|
create table public.users (
|
||||||
id uuid references auth.users not null primary key, -- UUID from auth.users
|
id uuid references auth.users not null primary key, -- UUID from auth.users
|
||||||
username text
|
username text
|
||||||
);
|
);
|
||||||
comment on table public.users is 'Profile data for each user.';
|
comment on table public.users is 'Profile data for each user.';
|
||||||
comment on column public.users.id is 'References the internal Supabase Auth user.';
|
comment on column public.users.id is 'References the internal Supabase Auth user.';
|
||||||
|
|
||||||
-- Roles
|
-- Roles
|
||||||
create table public.user_roles (
|
create table public.user_roles (
|
||||||
id bigint generated by default as identity primary key,
|
id bigint generated by default as identity primary key,
|
||||||
role app_role not null,
|
role app_role not null,
|
||||||
user_id uuid references public.users on delete cascade not null,
|
user_id uuid references public.users on delete cascade not null,
|
||||||
unique (user_id, role)
|
unique (user_id, role)
|
||||||
);
|
);
|
||||||
comment on table public.user_roles is 'Application roles for each user.';
|
comment on table public.user_roles is 'Application roles for each user.';
|
||||||
|
|
||||||
-- Permissions
|
-- Permissions
|
||||||
create table public.role_permissions (
|
create table public.role_permissions (
|
||||||
id bigint generated by default as identity primary key,
|
id bigint generated by default as identity primary key,
|
||||||
role app_role not null,
|
role app_role not null,
|
||||||
permission app_permission not null,
|
permission app_permission not null,
|
||||||
unique (role, permission)
|
unique (role, permission)
|
||||||
);
|
);
|
||||||
comment on table public.role_permissions is 'Application permissions for each role.';
|
comment on table public.role_permissions is 'Application permissions for each role.';
|
||||||
|
|
||||||
-- Worlds
|
-- Worlds
|
||||||
create table public.worlds (
|
create table public.worlds (
|
||||||
id bigint generated by default as identity primary key,
|
id bigint generated by default as identity primary key,
|
||||||
name text not null,
|
name text not null,
|
||||||
description text,
|
description text,
|
||||||
color app_colors default 'black',
|
color app_colors default 'black',
|
||||||
state world_state default 'draft',
|
state world_state default 'draft',
|
||||||
created_at timestamptz default now(),
|
created_at timestamptz default now(),
|
||||||
updated_at timestamptz,
|
updated_at timestamptz,
|
||||||
gm_id uuid references public.users on delete cascade
|
gm_id uuid references public.users on delete cascade
|
||||||
);
|
);
|
||||||
comment on table public.worlds is 'Worlds belonging to a single user ; a game master.';
|
comment on table public.worlds is 'Worlds belonging to a single user ; a game master.';
|
||||||
create trigger handle_updated_at before update on public.worlds
|
create trigger handle_updated_at before update on public.worlds
|
||||||
@@ -55,9 +55,9 @@ create trigger handle_updated_at before update on public.worlds
|
|||||||
|
|
||||||
-- World Players (join table)
|
-- World Players (join table)
|
||||||
create table public.world_players (
|
create table public.world_players (
|
||||||
world_id bigint references public.worlds on delete cascade,
|
world_id bigint references public.worlds on delete cascade,
|
||||||
player_id uuid references public.users on delete cascade,
|
player_id uuid references public.users on delete cascade,
|
||||||
joined_at timestamptz default now(),
|
joined_at timestamptz default now(),
|
||||||
primary key (world_id, player_id)
|
primary key (world_id, player_id)
|
||||||
);
|
);
|
||||||
comment on table public.world_players is 'Players (users) that belong to specific worlds';
|
comment on table public.world_players is 'Players (users) that belong to specific worlds';
|
||||||
@@ -91,27 +91,27 @@ comment on table public.calendar_months is 'A calendar month.';
|
|||||||
|
|
||||||
-- Calendar Event categories
|
-- Calendar Event categories
|
||||||
create table public.calendar_event_categories (
|
create table public.calendar_event_categories (
|
||||||
id bigint generated by default as identity primary key,
|
id bigint generated by default as identity primary key,
|
||||||
name text not null,
|
name text not null,
|
||||||
color app_colors default 'black',
|
color app_colors default 'black',
|
||||||
unique (name)
|
calendar_id bigint references public.calendars on delete cascade not null
|
||||||
);
|
);
|
||||||
comment on table public.calendar_event_categories is 'Categories describing events.';
|
comment on table public.calendar_event_categories is 'Categories describing events.';
|
||||||
|
|
||||||
-- Calendar Events
|
-- Calendar Events
|
||||||
create table public.calendar_events (
|
create table public.calendar_events (
|
||||||
id bigint generated by default as identity primary key,
|
id bigint generated by default as identity primary key,
|
||||||
title text not null,
|
title text not null,
|
||||||
description text,
|
description text,
|
||||||
location text,
|
location text,
|
||||||
start_date json not null,
|
start_date json not null,
|
||||||
end_date json,
|
end_date json,
|
||||||
category bigint references public.calendar_event_categories on delete cascade,
|
category bigint references public.calendar_event_categories on delete cascade,
|
||||||
hidden boolean default false,
|
hidden boolean default false,
|
||||||
wiki text,
|
wiki text,
|
||||||
created_at timestamptz default now(),
|
created_at timestamptz default now(),
|
||||||
updated_at timestamptz,
|
updated_at timestamptz,
|
||||||
calendar_id bigint references public.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';
|
comment on table public.calendar_events is 'Events linked to a world';
|
||||||
|
|
||||||
@@ -134,12 +134,12 @@ comment on table public.calendar_event_categories_links is 'Link tables for mult
|
|||||||
|
|
||||||
-- Character categories
|
-- Character categories
|
||||||
create table public.character_categories (
|
create table public.character_categories (
|
||||||
id bigint generated by default as identity primary key,
|
id bigint generated by default as identity primary key,
|
||||||
name text not null,
|
name text not null,
|
||||||
color app_colors default 'black',
|
color app_colors default 'black',
|
||||||
created_at timestamptz default now(),
|
created_at timestamptz default now(),
|
||||||
updated_at timestamptz,
|
updated_at timestamptz,
|
||||||
unique (name)
|
world_id bigint references public.worlds on delete cascade not null
|
||||||
);
|
);
|
||||||
comment on table public.character_categories is 'Categories describing characters';
|
comment on table public.character_categories is 'Categories describing characters';
|
||||||
|
|
||||||
@@ -420,12 +420,25 @@ create policy "Allow individual update access for GMs" on public.characters for
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Categories are public to view but not to insert
|
-- Categories policies
|
||||||
-- Needs to be refactored maybe, if in the future we want a default set AND user defined ones
|
create policy "Allow anonymous access to published event categories" on public.calendar_event_categories
|
||||||
create policy "Allow all read access" on public.calendar_event_categories for select to authenticated, anon using ( true );
|
for select
|
||||||
create policy "Allow all read access" on public.calendar_event_categories_links for select to authenticated, anon using ( true );
|
to authenticated, anon
|
||||||
create policy "Allow logged-in read access" on public.character_categories for select using ( auth.role() = 'authenticated' );
|
using (
|
||||||
create policy "Allow logged-in read access" on public.character_categories_links for select using ( auth.role() = 'authenticated' );
|
exists (
|
||||||
|
select 1
|
||||||
|
from public.calendars c
|
||||||
|
join public.calendar_event_categories_links l on l.calendar_event_category_id = calendar_event_categories.id
|
||||||
|
where c.id = calendar_event_categories.calendar_id
|
||||||
|
and c.state = 'published'
|
||||||
|
)
|
||||||
|
or exists (
|
||||||
|
select 1
|
||||||
|
from public.calendars c
|
||||||
|
where c.id = calendar_event_categories.calendar_id
|
||||||
|
and c.state = 'published'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
-- Send "previous data" on change
|
-- Send "previous data" on change
|
||||||
alter table public.users replica identity full;
|
alter table public.users replica identity full;
|
||||||
|
|||||||
@@ -1,57 +1,57 @@
|
|||||||
insert into public.role_permissions (role, permission) values ('sa', 'events.see.hidden');
|
insert into public.role_permissions (role, permission) values ('sa', 'events.see.hidden');
|
||||||
insert into public.role_permissions (role, permission) values ('sa', 'users.ban');
|
insert into public.role_permissions (role, permission) values ('sa', 'users.ban');
|
||||||
|
|
||||||
-- Event categories
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Naissance', 'white');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Mort', 'black');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Catastrophe', 'orange');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Catastrophe naturelle', 'red');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Inauguration', 'green');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Religion', 'violet');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Invention', 'teal');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Science', 'indigo');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Bénédiction', 'white');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Joueurs', 'white');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Découverte', 'purple');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Exploration', 'lime');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Construction', 'blue');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Arcanologie', 'cyan');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Criminalité', 'rose');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Scandale', 'pink');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Commerce', 'amber');
|
|
||||||
insert into public.calendar_event_categories (name, color) values ('Législation', 'blue');
|
|
||||||
|
|
||||||
-- Character categories
|
|
||||||
insert into public.character_categories (name, color) values ('Joueur', 'white');
|
|
||||||
insert into public.character_categories (name, color) values ('Comte', 'emerald');
|
|
||||||
insert into public.character_categories (name, color) values ('Scientifique', 'indigo');
|
|
||||||
insert into public.character_categories (name, color) values ('Mage', 'cyan');
|
|
||||||
insert into public.character_categories (name, color) values ('Professeur', 'teal');
|
|
||||||
insert into public.character_categories (name, color) values ('Criminel', 'rose');
|
|
||||||
insert into public.character_categories (name, color) values ('Étincelle', 'lime');
|
|
||||||
insert into public.character_categories (name, color) values ('Buse blanche', 'yellow');
|
|
||||||
insert into public.character_categories (name, color) values ('Ecclésiastique', 'violet');
|
|
||||||
insert into public.character_categories (name, color) values ('Militaire', 'orange');
|
|
||||||
insert into public.character_categories (name, color) values ('Activiste', 'sky');
|
|
||||||
insert into public.character_categories (name, color) values ('Commerçant', 'amber');
|
|
||||||
|
|
||||||
-- Worlds
|
-- Worlds
|
||||||
insert into public.worlds (name, description, color, state) values ('Léïm', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis aliquet congue aliquet. Curabitur eu iaculis diam. Nunc iaculis nibh orci, eu semper nunc congue congue. Praesent euismod tortor eget metus tristique lobortis vel in risus. In volutpat ligula orci, id pharetra lectus egestas at.', 'black', 'published');
|
insert into public.worlds (name, description, color, state) values ('Léïm', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis aliquet congue aliquet. Curabitur eu iaculis diam. Nunc iaculis nibh orci, eu semper nunc congue congue. Praesent euismod tortor eget metus tristique lobortis vel in risus. In volutpat ligula orci, id pharetra lectus egestas at.', 'black', 'published');
|
||||||
|
|
||||||
|
-- Character categories
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Joueur', 'white', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Comte', 'emerald', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Scientifique', 'indigo', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Mage', 'cyan', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Professeur', 'teal', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Criminel', 'rose', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Étincelle', 'lime', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Buse blanche', 'yellow', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Ecclésiastique', 'violet', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Militaire', 'orange', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Activiste', 'sky', 1);
|
||||||
|
insert into public.character_categories (name, color, world_id) values ('Commerçant', 'amber', 1);
|
||||||
|
|
||||||
-- Worlds' calendars
|
-- Worlds' calendars
|
||||||
insert into public.calendars (world_id, name, today, state) values (1, 'Calendrier solaire', '{ "day": 23, "month": 8, "year": 3209 }', 'published');
|
insert into public.calendars (world_id, name, today, state) values (1, 'Calendrier solaire', '{ "day": 23, "month": 8, "year": 3209 }', 'published');
|
||||||
|
|
||||||
-- Calendar's months
|
-- Calendar's months
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Jalen', 32, 1);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Jalen', 32, 1, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Malsen', 32, 2);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Malsen', 32, 2, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Verlys', 32, 3);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Verlys', 32, 3, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Nalys', 32, 4);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Nalys', 32, 4, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Verdore', 32, 5);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Verdore', 32, 5, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Sidore', 32, 6);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Sidore', 32, 6, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Lyllion', 32, 7);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Lyllion', 32, 7, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Rion', 32, 8);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Rion', 32, 8, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Farene', 32, 9);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Farene', 32, 9, 1);
|
||||||
insert into public.calendar_months (calendar_id, name, days, position) values (1, 'Dalvene', 32, 10);
|
insert into public.calendar_months (name, days, position, calendar_id) values ('Dalvene', 32, 10, 1);
|
||||||
|
|
||||||
|
-- Event categories
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Naissance', 'white', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Mort', 'black', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Catastrophe', 'orange', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Catastrophe naturelle', 'red', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Inauguration', 'green', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Religion', 'violet', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Invention', 'teal', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Science', 'indigo', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Bénédiction', 'white', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Joueurs', 'white', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Découverte', 'purple', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Exploration', 'lime', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Construction', 'blue', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Magie', 'cyan', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Criminalité', 'rose', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Scandale', 'pink', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Commerce', 'amber', 1);
|
||||||
|
insert into public.calendar_event_categories (name, color, calendar_id) values ('Législation', 'blue', 1);
|
||||||
|
|
||||||
-- Events
|
-- Events
|
||||||
insert into public.calendar_events (title, description, start_date, category, hidden, wiki, calendar_id) values (
|
insert into public.calendar_events (title, description, start_date, category, hidden, wiki, calendar_id) values (
|
||||||
@@ -203,7 +203,7 @@ insert into public.calendar_events (title, description, start_date, end_date, ca
|
|||||||
'Celui qu''on surnomme la Bête d''Ambrose arrive à Handany, où il purgera sa peine.',
|
'Celui qu''on surnomme la Bête d''Ambrose arrive à Handany, où il purgera sa peine.',
|
||||||
'{ "day": 14, "month": 7, "year": 3209 }',
|
'{ "day": 14, "month": 7, "year": 3209 }',
|
||||||
null,
|
null,
|
||||||
18,
|
15,
|
||||||
false,
|
false,
|
||||||
'https://alexcreates.fr/leim/index.php/Tivian_Rodhus',
|
'https://alexcreates.fr/leim/index.php/Tivian_Rodhus',
|
||||||
1
|
1
|
||||||
@@ -221,7 +221,7 @@ insert into public.calendar_events (title, description, location, start_date, en
|
|||||||
'Tourgrise',
|
'Tourgrise',
|
||||||
'{ "day": 4, "month": 8, "year": 3209 }',
|
'{ "day": 4, "month": 8, "year": 3209 }',
|
||||||
null,
|
null,
|
||||||
18,
|
15,
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
1
|
1
|
||||||
@@ -245,7 +245,7 @@ insert into public.calendar_events (title, description, location, start_date, en
|
|||||||
'{ "day": 28, "month": 7, "year": 3209 }',
|
'{ "day": 28, "month": 7, "year": 3209 }',
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
true,
|
false,
|
||||||
null,
|
null,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
@@ -256,7 +256,7 @@ insert into public.calendar_events (title, description, location, start_date, en
|
|||||||
'{ "day": 32, "month": 7, "year": 3209 }',
|
'{ "day": 32, "month": 7, "year": 3209 }',
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
true,
|
false,
|
||||||
null,
|
null,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
@@ -267,7 +267,7 @@ insert into public.calendar_events (title, description, location, start_date, en
|
|||||||
'{ "day": 10, "month": 8, "year": 3209 }',
|
'{ "day": 10, "month": 8, "year": 3209 }',
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
true,
|
false,
|
||||||
null,
|
null,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
@@ -278,7 +278,7 @@ insert into public.calendar_events (title, description, location, start_date, en
|
|||||||
'{ "day": 19, "month": 8, "year": 3209 }',
|
'{ "day": 19, "month": 8, "year": 3209 }',
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
true,
|
false,
|
||||||
null,
|
null,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
@@ -289,7 +289,7 @@ insert into public.calendar_events (title, description, location, start_date, en
|
|||||||
'{ "day": 22, "month": 8, "year": 3209 }',
|
'{ "day": 22, "month": 8, "year": 3209 }',
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
true,
|
false,
|
||||||
null,
|
null,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user