[BE-DB-007] be-db: Create migration for user_blocks table
This commit is contained in:
parent
c1f6e93c95
commit
5c8a49d4f5
2 changed files with 39 additions and 2 deletions
|
|
@ -3140,7 +3140,7 @@
|
||||||
"description": "Add table for user block relationships",
|
"description": "Add table for user block relationships",
|
||||||
"owner": "backend",
|
"owner": "backend",
|
||||||
"estimated_hours": 2,
|
"estimated_hours": 2,
|
||||||
"status": "todo",
|
"status": "completed",
|
||||||
"files_involved": [],
|
"files_involved": [],
|
||||||
"implementation_steps": [
|
"implementation_steps": [
|
||||||
{
|
{
|
||||||
|
|
@ -3161,7 +3161,9 @@
|
||||||
"Unit tests",
|
"Unit tests",
|
||||||
"Integration 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",
|
"id": "BE-DB-008",
|
||||||
|
|
|
||||||
35
veza-backend-api/migrations/046_user_blocks.sql
Normal file
35
veza-backend-api/migrations/046_user_blocks.sql
Normal file
|
|
@ -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';
|
||||||
|
|
||||||
Loading…
Reference in a new issue