Files
thrilltrack-explorer/supabase/migrations/20251030120117_ba8dcb4e-b12c-4f86-9a71-61e752a280ca.sql
2025-10-30 12:03:55 +00:00

23 lines
829 B
SQL

-- Add ban expiration tracking
ALTER TABLE public.profiles
ADD COLUMN IF NOT EXISTS ban_expires_at timestamptz;
COMMENT ON COLUMN public.profiles.ban_expires_at IS
'When the ban expires (null = permanent ban). Automatic unbanning is handled by a scheduled edge function.';
-- Update existing banned users to have a default ban reason
UPDATE public.profiles
SET ban_reason = 'No reason provided (legacy ban)'
WHERE banned = true AND (ban_reason IS NULL OR ban_reason = '');
-- Add constraint to require ban_reason when banned
ALTER TABLE public.profiles
ADD CONSTRAINT ban_reason_required
CHECK (
(banned = true AND ban_reason IS NOT NULL AND ban_reason != '')
OR
(banned = false)
);
COMMENT ON CONSTRAINT ban_reason_required ON public.profiles IS
'Ensures that a ban reason must be provided when banning a user';