feat(classes): migration 037 classes.required_form_id (optional form gate)

Nullable FK classes.required_form_id -> forms(id) ON DELETE SET NULL.
Mirrored in schema.sql, types, DATABASE_SCHEMA, DB_SCHEMA_MAP. Additive
nullable column on the already-policied classes table (no RLS change);
the signup gate is enforced in the app, mirroring the equipment cert-gate.
This commit is contained in:
Moheeb Zara
2026-05-16 21:33:53 -07:00
parent 268d78dd6d
commit 92c5737a25
5 changed files with 33 additions and 5 deletions
+25
View File
@@ -0,0 +1,25 @@
-- =============================================================================
-- 037: A class can optionally require a form
-- =============================================================================
-- A class may point at one form in the same space (a waiver or intake form).
-- When set, signing up for any session of that class requires the member to
-- have a completed submission of that form on file (the "waiver on file"
-- model). The gate is enforced in the application
-- (lib/classes-logic.ts + lib/actions/classes.ts), mirroring the existing
-- equipment required-certification gate: a classes.manage holder can override
-- and sign a member up on their behalf. The submission check reads
-- form_submissions via the service client (boolean only) since a class
-- manager need not hold forms.manage.
--
-- ON DELETE SET NULL: deleting the form just drops the requirement; existing
-- signups are unaffected.
--
-- No RLS change: classes already has additive default-deny policies and this
-- is an additional nullable column on it.
--
-- Idempotent: ADD COLUMN IF NOT EXISTS.
-- =============================================================================
ALTER TABLE public.classes
ADD COLUMN IF NOT EXISTS required_form_id uuid
REFERENCES public.forms(id) ON DELETE SET NULL;
+1
View File
@@ -2115,6 +2115,7 @@ CREATE TABLE IF NOT EXISTS public.classes (
capacity integer CHECK (capacity IS NULL OR capacity > 0),
is_active boolean NOT NULL DEFAULT true,
grants_certification_id uuid REFERENCES public.certifications(id) ON DELETE SET NULL,
required_form_id uuid REFERENCES public.forms(id) ON DELETE SET NULL,
created_by uuid REFERENCES public.space_members(id) ON DELETE SET NULL,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()