[BE-DB-006] be-db: Create migration for user_follows table
This commit is contained in:
parent
6795191696
commit
eb5b9f6483
2 changed files with 35 additions and 2 deletions
|
|
@ -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",
|
||||
|
|
|
|||
31
veza-backend-api/migrations/045_user_follows.sql
Normal file
31
veza-backend-api/migrations/045_user_follows.sql
Normal file
|
|
@ -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';
|
||||
|
||||
Loading…
Reference in a new issue