Files

28 lines
1.3 KiB
SQL

-- =============================================================================
-- MC Cars - Add per-vehicle kaution (deposit) and max_km_weekend columns.
-- Idempotent.
-- =============================================================================
-- -----------------------------------------------------------------------------
-- 1. kaution_eur: deposit per vehicle, NOT NULL, default 5000, must be > 0
-- -----------------------------------------------------------------------------
alter table public.vehicles add column if not exists kaution_eur integer not null default 5000;
do $$
begin
if not exists (
select 1 from information_schema.check_constraints
where constraint_name = 'vehicles_kaution_positive'
) then
alter table public.vehicles add constraint vehicles_kaution_positive check (kaution_eur > 0);
end if;
end $$;
-- -----------------------------------------------------------------------------
-- 2. max_km_weekend: optional per-weekend-day km allowance (NULL = use max_daily_km)
-- -----------------------------------------------------------------------------
alter table public.vehicles add column if not exists max_km_weekend integer default null;
-- Signal PostgREST to reload its schema cache
notify pgrst, 'reload schema';