-- Vertretungen können auch Personen sein. -- ==================================================================== -- Bisher: deputies.deputy_position_id (NOT NULL) — eine Stelle vertritt -- eine andere Stelle. -- -- Erweiterung: deputy_employee_id (nullable) — eine Stelle wird von -- einer konkreten Person vertreten, ohne dass diese Person eine eigene -- Stelle haben muss. Anwendungsfall: Mitarbeiter wie P. Schmid stehen -- offiziell auf "Strom-Netz", vertreten aber die Leitung Strom-Netz. -- -- CHECK-Constraint stellt sicher: genau eines von beiden ist gesetzt. alter table public.deputies add column if not exists deputy_employee_id uuid references public.employees(id) on delete cascade; alter table public.deputies alter column deputy_position_id drop not null; alter table public.deputies drop constraint if exists deputies_target_check; alter table public.deputies add constraint deputies_target_check check ( (deputy_position_id is not null)::int + (deputy_employee_id is not null)::int = 1 ); create index if not exists deputies_deputy_employee_idx on public.deputies (deputy_employee_id);