-- Migration: Add user_id to custom_templates
-- Purpose: Track which authenticated user created a custom template

-- Add column if it does not exist
ALTER TABLE IF EXISTS custom_templates
ADD COLUMN IF NOT EXISTS user_id UUID NULL;

-- Optional: add an index for filtering by user
CREATE INDEX IF NOT EXISTS idx_custom_templates_user_id ON custom_templates(user_id);

-- Note: We are not adding a foreign key constraint because the users table
-- may be managed by a different service/schema. If later a shared users table
-- is available, a FK can be added safely.

SELECT 'user_id column added to custom_templates' AS message;


