1
0
Fork 0

feat: add orte and fahrzeuge lookup tables with RLS

This commit is contained in:
Jonny 2026-07-05 10:59:55 +02:00
parent f9bddc01a8
commit 0850f0ccfc
1 changed files with 50 additions and 0 deletions

View File

@ -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'));