{"-- 1) Add zoom to pinned_dashboards
ALTER TABLE public.pinned_dashboards
ADD COLUMN IF NOT EXISTS zoom NUMERIC NOT NULL DEFAULT 1.0","-- 2) Create labels table for canvas annotations
CREATE TABLE IF NOT EXISTS public.pinned_labels (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id UUID NOT NULL,
  text TEXT NOT NULL DEFAULT 'Label',
  color TEXT NOT NULL DEFAULT '#111827',
  font_size INTEGER NOT NULL DEFAULT 16,
  x INTEGER NOT NULL DEFAULT 40,
  y INTEGER NOT NULL DEFAULT 40,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
)","-- Enable RLS
ALTER TABLE public.pinned_labels ENABLE ROW LEVEL SECURITY","-- Drop existing policies
DO $$
DECLARE r record;
BEGIN
  FOR r IN SELECT policyname FROM pg_policies WHERE tablename='pinned_labels' AND schemaname='public' LOOP
    EXECUTE format('DROP POLICY %I ON public.pinned_labels', r.policyname);
  END LOOP;
END $$","-- Create policies
CREATE POLICY \"Labels: users can view their own\"
ON public.pinned_labels FOR SELECT
USING (auth.uid() = user_id)","CREATE POLICY \"Labels: users can insert their own\"
ON public.pinned_labels FOR INSERT
WITH CHECK (auth.uid() = user_id)","CREATE POLICY \"Labels: users can update their own\"
ON public.pinned_labels FOR UPDATE
USING (auth.uid() = user_id)","CREATE POLICY \"Labels: users can delete their own\"
ON public.pinned_labels FOR DELETE
USING (auth.uid() = user_id)","-- Trigger to keep updated_at fresh (uses existing update_modified_column function)
DROP TRIGGER IF EXISTS trg_pinned_labels_updated_at ON public.pinned_labels","CREATE TRIGGER trg_pinned_labels_updated_at
BEFORE UPDATE ON public.pinned_labels
FOR EACH ROW EXECUTE FUNCTION public.update_modified_column()","-- Helpful index for user_id lookup
CREATE INDEX IF NOT EXISTS idx_pinned_labels_user_id ON public.pinned_labels(user_id)"}