-- Migration 005: Add consent management fields to groups table
-- Date: 2025-11-09
-- Description: Adds fields for workshop display consent, consent timestamp, and management token

-- Add consent-related columns to groups table
ALTER TABLE groups ADD COLUMN display_in_workshop BOOLEAN NOT NULL DEFAULT 0;
ALTER TABLE groups ADD COLUMN consent_timestamp DATETIME;
ALTER TABLE groups ADD COLUMN management_token TEXT; -- For Phase 2: Self-service portal

-- Create indexes for better query performance
CREATE INDEX IF NOT EXISTS idx_groups_display_consent ON groups(display_in_workshop);
CREATE UNIQUE INDEX IF NOT EXISTS idx_groups_management_token ON groups(management_token) WHERE management_token IS NOT NULL;

-- IMPORTANT: Do NOT update existing groups!
-- Old groups (before this migration) never gave explicit consent.
-- They must remain with display_in_workshop = 0 for GDPR compliance.
-- Only NEW uploads (after this migration) will have explicit consent via the upload form.
-- Existing groups can be manually reviewed and consent can be granted by admins if needed.
