diff --git a/VEZA_COMPLETE_MVP_TODOLIST.json b/VEZA_COMPLETE_MVP_TODOLIST.json index f07dbb589..0f8e2bb2a 100644 --- a/VEZA_COMPLETE_MVP_TODOLIST.json +++ b/VEZA_COMPLETE_MVP_TODOLIST.json @@ -3105,7 +3105,7 @@ "description": "Add table for user follow relationships", "owner": "backend", "estimated_hours": 2, - "status": "todo", + "status": "completed", "files_involved": [], "implementation_steps": [ { @@ -3126,7 +3126,9 @@ "Unit tests", "Integration tests" ], - "notes": "" + "notes": "", + "completed_at": "2025-12-24T15:10:33.329280", + "implementation_notes": "Created migration 045_user_follows.sql for follows table (user follow relationships). Migration includes: id (UUID), follower_id (FK to users), followed_id (FK to users), timestamps (created_at, updated_at), unique constraint on (follower_id, followed_id), check constraint to prevent self-follow, and appropriate indexes. Table name is \"follows\" as used by SocialService." }, { "id": "BE-DB-007", diff --git a/veza-backend-api/migrations/045_user_follows.sql b/veza-backend-api/migrations/045_user_follows.sql new file mode 100644 index 000000000..eaa9df2f2 --- /dev/null +++ b/veza-backend-api/migrations/045_user_follows.sql @@ -0,0 +1,31 @@ +-- 045_user_follows.sql +-- User Follow Relationships (BE-DB-006: Create migration for user_follows table) +-- Add table for user follow relationships + +-- === USER FOLLOWS === +-- Table for tracking user-to-user follow relationships +CREATE TABLE IF NOT EXISTS public.follows ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + follower_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + followed_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE, + + -- Timestamps + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + + -- Constraints + CONSTRAINT uq_follows_follower_followed UNIQUE (follower_id, followed_id), + CONSTRAINT chk_follows_not_self CHECK (follower_id != followed_id) +); + +-- Indexes +CREATE INDEX IF NOT EXISTS idx_follows_follower_id ON public.follows(follower_id); +CREATE INDEX IF NOT EXISTS idx_follows_followed_id ON public.follows(followed_id); +CREATE INDEX IF NOT EXISTS idx_follows_created_at_desc ON public.follows(created_at DESC); + +-- Comments +COMMENT ON TABLE public.follows IS 'User-to-user follow relationships'; +COMMENT ON COLUMN public.follows.follower_id IS 'ID of the user who is following'; +COMMENT ON COLUMN public.follows.followed_id IS 'ID of the user being followed'; +COMMENT ON CONSTRAINT chk_follows_not_self ON public.follows IS 'Prevents users from following themselves'; +