since3-portal/lib/supabase/migrations/20260930100000_info_section.sql
2026-09-29 15:20:50 +02:00

37 lines
1.4 KiB
PL/PgSQL

-- Info-Sektion: Produktstatus, laufende Vorgänge, interne Notizen
-- Hosting als eigene Kategorie (neben Webseite, E-Mail, SEO)
alter type public.product_category add value if not exists 'hosting';
-- Freitext zum Status, z. B. "Erreichbar, keine Störungen" oder "Wartung geplant am 12.10."
alter table public.client_products
add column if not exists status_message text;
-- Vorgänge müssen nicht zwingend an ein Produkt gebunden sein
alter table public.product_tasks
alter column product_id drop not null;
-- "zuletzt bearbeitet von ..." für interne Notizen
alter table public.internal_notes
add column if not exists updated_by uuid references public.profiles(id) on delete set null default auth.uid(),
add column if not exists updated_at timestamptz not null default now();
update public.internal_notes
set updated_by = created_by, updated_at = created_at
where updated_by is null;
create or replace function public.set_updated_by()
returns trigger language plpgsql set search_path = '' as $$
begin
new.updated_by = auth.uid();
return new;
end $$;
create trigger set_updated_at before update on public.internal_notes
for each row execute function public.set_updated_at();
create trigger set_updated_by before update on public.internal_notes
for each row execute function public.set_updated_by();
create index if not exists internal_notes_client_updated_idx
on public.internal_notes (client_id, updated_at desc);