Social Media Database Schema (SQL + ERD + Prisma)
Output
SQL schema sample
CREATE TABLE users (id UUID PRIMARY KEY, username TEXT UNIQUE NOT NULL); CREATE TABLE posts (id UUID PRIMARY KEY, author_id UUID REFERENCES users(id), body TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW()); CREATE TABLE comments (id UUID PRIMARY KEY, post_id UUID REFERENCES posts(id), author_id UUID REFERENCES users(id), body TEXT NOT NULL); CREATE TABLE follows (follower_id UUID REFERENCES users(id), followee_id UUID REFERENCES users(id), PRIMARY KEY(follower_id, followee_id));
Diagram
users 1---* posts posts 1---* comments users *---* users (via follows)
Use this as a base for feed ranking, notifications, and moderation workflows.