diff --git a/VEZA_COMPLETE_MVP_TODOLIST.json b/VEZA_COMPLETE_MVP_TODOLIST.json index 0f8e2bb2a..ab7d692ab 100644 --- a/VEZA_COMPLETE_MVP_TODOLIST.json +++ b/VEZA_COMPLETE_MVP_TODOLIST.json @@ -3140,7 +3140,7 @@ "description": "Add table for user block relationships", "owner": "backend", "estimated_hours": 2, - "status": "todo", + "status": "completed", "files_involved": [], "implementation_steps": [ { @@ -3161,7 +3161,9 @@ "Unit tests", "Integration tests" ], - "notes": "" + "notes": "", + "completed_at": "2025-12-24T15:11:31.971623", + "implementation_notes": "Created migration 046_user_blocks.sql for user_blocks table. Migration includes: id (UUID), blocker_id (FK to users), blocked_id (FK to users), reason (optional VARCHAR), timestamps (created_at, updated_at), unique constraint on (blocker_id, blocked_id), check constraint to prevent self-block, and appropriate indexes. Table name is \"user_blocks\" as used by SocialService." }, { "id": "BE-DB-008", diff --git a/veza-backend-api/migrations/046_user_blocks.sql b/veza-backend-api/migrations/046_user_blocks.sql new file mode 100644 index 000000000..47eb0cab8 --- /dev/null +++ b/veza-backend-api/migrations/046_user_blocks.sql @@ -0,0 +1,35 @@ +-- 046_user_blocks.sql +-- User Block Relationships (BE-DB-007: Create migration for user_blocks table) +-- Add table for user block relationships + +-- === USER BLOCKS === +-- Table for tracking user-to-user block relationships +CREATE TABLE IF NOT EXISTS public.user_blocks ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + blocker_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + blocked_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + + -- Optional reason for blocking + reason VARCHAR(255), + + -- Timestamps + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + + -- Constraints + CONSTRAINT uq_user_blocks_blocker_blocked UNIQUE (blocker_id, blocked_id), + CONSTRAINT chk_user_blocks_not_self CHECK (blocker_id != blocked_id) +); + +-- Indexes +CREATE INDEX IF NOT EXISTS idx_user_blocks_blocker_id ON public.user_blocks(blocker_id); +CREATE INDEX IF NOT EXISTS idx_user_blocks_blocked_id ON public.user_blocks(blocked_id); +CREATE INDEX IF NOT EXISTS idx_user_blocks_created_at_desc ON public.user_blocks(created_at DESC); + +-- Comments +COMMENT ON TABLE public.user_blocks IS 'User-to-user block relationships'; +COMMENT ON COLUMN public.user_blocks.blocker_id IS 'ID of the user who is blocking'; +COMMENT ON COLUMN public.user_blocks.blocked_id IS 'ID of the user being blocked'; +COMMENT ON COLUMN public.user_blocks.reason IS 'Optional reason for blocking'; +COMMENT ON CONSTRAINT chk_user_blocks_not_self ON public.user_blocks IS 'Prevents users from blocking themselves'; +