diff --git a/supabase/migrations/20260705085814_orte_fahrzeuge.sql b/supabase/migrations/20260705085814_orte_fahrzeuge.sql new file mode 100644 index 0000000..d98beef --- /dev/null +++ b/supabase/migrations/20260705085814_orte_fahrzeuge.sql @@ -0,0 +1,50 @@ +create table public.orte ( + id uuid primary key default gen_random_uuid(), + adresse text not null, + ansprechpartner text not null, + created_by uuid references public.profiles (id), + created_at timestamptz not null default now() +); + +create table public.fahrzeuge ( + id uuid primary key default gen_random_uuid(), + kennzeichen text not null unique, + marke text, + modell text, + created_at timestamptz not null default now() +); + +alter table public.orte enable row level security; +alter table public.fahrzeuge enable row level security; + +-- RLS wirkt nur zusaetzlich zu den normalen Postgres-Privilegien (siehe +-- 20260704095119_rls_profiles.sql) -- ohne GRANT bekaeme `authenticated` +-- weiterhin "permission denied", auch mit passenden Policies. +grant select, insert, update on public.orte to authenticated; +grant select, insert, update on public.fahrzeuge to authenticated; + +create policy "Eingeloggte Nutzer sehen alle Orte" + on public.orte for select + using (public.user_role() in ('admin', 'disponent', 'fahrer', 'readonly')); + +create policy "Disponent und Admin legen Orte an" + on public.orte for insert + with check (public.user_role() in ('admin', 'disponent')); + +create policy "Disponent und Admin bearbeiten Orte" + on public.orte for update + using (public.user_role() in ('admin', 'disponent')) + with check (public.user_role() in ('admin', 'disponent')); + +create policy "Eingeloggte Nutzer sehen alle Fahrzeuge" + on public.fahrzeuge for select + using (public.user_role() in ('admin', 'disponent', 'fahrer', 'readonly')); + +create policy "Disponent und Admin legen Fahrzeuge an" + on public.fahrzeuge for insert + with check (public.user_role() in ('admin', 'disponent')); + +create policy "Disponent und Admin bearbeiten Fahrzeuge" + on public.fahrzeuge for update + using (public.user_role() in ('admin', 'disponent')) + with check (public.user_role() in ('admin', 'disponent'));