Fix: Correct ban migration logic

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 12:03:55 +00:00
parent e5de404e59
commit db101bc5f2
8 changed files with 509 additions and 52 deletions

View File

@@ -0,0 +1,23 @@
-- 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';