V1
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
-- =====================================================================
|
||||
-- GameDev Tracker — Migration v2
|
||||
-- À exécuter UNE FOIS dans : Supabase > SQL Editor > New query
|
||||
-- (pour une base déjà créée avec schema.sql v1)
|
||||
--
|
||||
-- Contenu :
|
||||
-- • Suppression des JALONS (milestones)
|
||||
-- • Notion de PÔLE sur les tâches et les bugs
|
||||
-- • Plusieurs personnes assignables sur une tâche (assignee_ids)
|
||||
-- • Système de NOTIFICATIONS (assignation à un pôle)
|
||||
-- =====================================================================
|
||||
|
||||
-- ---------- Pôle sur tâches & bugs (réutilise l'enum member_role) -----
|
||||
alter table public.tasks add column if not exists pole member_role;
|
||||
alter table public.bugs add column if not exists pole member_role;
|
||||
|
||||
-- ---------- Plusieurs assignés par tâche -----------------------------
|
||||
alter table public.tasks
|
||||
add column if not exists assignee_ids uuid[] not null default '{}';
|
||||
|
||||
-- Reprend l'assigné unique existant dans le nouveau tableau.
|
||||
update public.tasks
|
||||
set assignee_ids = array[assignee_id]
|
||||
where assignee_id is not null
|
||||
and (assignee_ids is null or assignee_ids = '{}');
|
||||
|
||||
alter table public.tasks drop column if exists assignee_id;
|
||||
|
||||
-- ---------- Suppression des jalons -----------------------------------
|
||||
alter table public.tasks drop column if exists milestone_id;
|
||||
drop table if exists public.milestones cascade;
|
||||
drop type if exists milestone_status;
|
||||
|
||||
-- ---------- Notifications --------------------------------------------
|
||||
create table if not exists public.notifications (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
user_id uuid not null references public.profiles(id) on delete cascade,
|
||||
project_id uuid references public.projects(id) on delete cascade,
|
||||
kind text not null, -- 'task' | 'bug'
|
||||
title text not null, -- ex : « Nouvelle tâche »
|
||||
body text, -- titre de la tâche / du bug
|
||||
entity_id uuid, -- id de la tâche / du bug
|
||||
pole member_role, -- pôle destinataire
|
||||
read boolean not null default false,
|
||||
created_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create index if not exists idx_notifications_user on public.notifications(user_id);
|
||||
|
||||
alter table public.notifications enable row level security;
|
||||
|
||||
-- Chacun lit/modifie SES notifications ; l'insertion est ouverte à tout
|
||||
-- membre connecté (afin de notifier les autres membres d'un pôle).
|
||||
drop policy if exists notifications_select on public.notifications;
|
||||
drop policy if exists notifications_insert on public.notifications;
|
||||
drop policy if exists notifications_update on public.notifications;
|
||||
drop policy if exists notifications_delete on public.notifications;
|
||||
|
||||
create policy notifications_select on public.notifications
|
||||
for select to authenticated using (user_id = auth.uid());
|
||||
create policy notifications_insert on public.notifications
|
||||
for insert to authenticated with check (true);
|
||||
create policy notifications_update on public.notifications
|
||||
for update to authenticated using (user_id = auth.uid()) with check (user_id = auth.uid());
|
||||
create policy notifications_delete on public.notifications
|
||||
for delete to authenticated using (user_id = auth.uid());
|
||||
|
||||
do $$ begin
|
||||
alter publication supabase_realtime add table public.notifications;
|
||||
exception when duplicate_object then null; end $$;
|
||||
Reference in New Issue
Block a user