
-- Student Proofs table
CREATE TABLE public.student_proofs (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  image_url text NOT NULL,
  caption text,
  position integer NOT NULL DEFAULT 0,
  is_published boolean NOT NULL DEFAULT true,
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);
GRANT SELECT ON public.student_proofs TO anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON public.student_proofs TO authenticated;
GRANT ALL ON public.student_proofs TO service_role;
ALTER TABLE public.student_proofs ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Anyone reads published proofs" ON public.student_proofs FOR SELECT TO anon, authenticated USING (is_published OR has_role(auth.uid(), 'admin'));
CREATE POLICY "Admins manage proofs" ON public.student_proofs FOR ALL TO authenticated USING (has_role(auth.uid(), 'admin')) WITH CHECK (has_role(auth.uid(), 'admin'));
CREATE TRIGGER update_student_proofs_updated_at BEFORE UPDATE ON public.student_proofs FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();

-- Tracking columns on site_settings
ALTER TABLE public.site_settings
  ADD COLUMN fb_pixel_id text,
  ADD COLUMN fb_pixel_enabled boolean NOT NULL DEFAULT false,
  ADD COLUMN tiktok_pixel_id text,
  ADD COLUMN tiktok_pixel_enabled boolean NOT NULL DEFAULT false,
  ADD COLUMN ga_measurement_id text,
  ADD COLUMN ga_enabled boolean NOT NULL DEFAULT false;
