-- Migration: Add Terms of Service acceptance fields to users table
--
-- This migration adds:
-- - accepts_tos: Boolean field to track ToS acceptance
-- - tos_accepted_at: Timestamp of when user accepted ToS

-- Add accepts_tos column (Boolean, default False)
ALTER TABLE users
ADD COLUMN accepts_tos BOOLEAN DEFAULT FALSE NOT NULL;

-- Add tos_accepted_at column (nullable timestamp)
ALTER TABLE users
ADD COLUMN tos_accepted_at TIMESTAMP WITH TIME ZONE;

-- Backfill existing users: mark as accepted with created_at date
-- This is reasonable since existing users registered before ToS requirement
UPDATE users
SET accepts_tos = TRUE,
    tos_accepted_at = created_at
WHERE created_at IS NOT NULL;

-- Success message
SELECT 'Migration completed: ToS acceptance fields added to users table' AS result;
