Files
accounted/supabase/migrations/20260421170000_booking_template_usage_updated_at.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

25 lines
1.1 KiB
SQL

-- =============================================================================
-- Booking Template Usage: add updated_at column + trigger
-- =============================================================================
--
-- Follow-up to 20260421160000_booking_template_usage.sql. The project
-- migration rules (CLAUDE.md) require every table to carry an updated_at
-- column maintained by the shared update_updated_at_column() trigger. The
-- initial migration omitted it because the row is touched via upsert
-- (which bumps last_used_at) — but the audit convention applies regardless.
ALTER TABLE public.booking_template_usage
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
-- Seed updated_at for existing rows to match last_used_at so history is
-- coherent from day one.
UPDATE public.booking_template_usage
SET updated_at = last_used_at
WHERE updated_at < last_used_at;
CREATE TRIGGER btu_updated_at
BEFORE UPDATE ON public.booking_template_usage
FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();
NOTIFY pgrst, 'reload schema';