-- Migration: Add is_custom flag to custom_templates

-- Add column if it doesn't exist
DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = 'public'
      AND table_name = 'custom_templates'
      AND column_name = 'is_custom'
  ) THEN
    ALTER TABLE custom_templates
      ADD COLUMN is_custom BOOLEAN NOT NULL DEFAULT false;
  END IF;
END $$;

-- Backfill: ensure all existing rows default to false
UPDATE custom_templates SET is_custom = COALESCE(is_custom, false);

-- Success message
SELECT 'is_custom flag added to custom_templates' as message;


