Reviews & ratings database schema
Businesses reviewed by users, with photos, helpful votes and owner replies.
6 tables, 6 relationships
Opens as a new diagram you can change. Free.
Tables
users
- iduuid not null
- display_nametext not null
- emailtext not null
- created_attimestamptz not null
businesses
- iduuid not null
- nametext not null
- categorytext not null
- addresstext not null
- created_attimestamptz not null
reviews
- iduuid not null
- business_id> businessesuuid not null
- author_id> usersuuid not null
- ratinginteger not null
- bodytext not null
- created_attimestamptz not null
review_photos
- iduuid not null
- review_id> reviewsuuid not null
- urltext not null
- created_attimestamptz not null
review_votes
- iduuid not null
- review_id> reviewsuuid not null
- user_id> usersuuid not null
- helpfulboolean not null
- created_attimestamptz not null
owner_replies
- iduuid not null
- review_id> reviewsuuid not null
- bodytext not null
- created_attimestamptz not null
As PostgreSQL
The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.
CREATE TABLE "businesses" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"category" TEXT NOT NULL,
"address" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "owner_replies" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"review_id" UUID NOT NULL UNIQUE,
"body" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "review_photos" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"review_id" UUID NOT NULL,
"url" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "review_votes" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"review_id" UUID NOT NULL,
"user_id" UUID NOT NULL,
"helpful" BOOLEAN NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "reviews" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"business_id" UUID NOT NULL,
"author_id" UUID NOT NULL,
"rating" INTEGER NOT NULL,
"body" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "users" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"display_name" TEXT NOT NULL,
"email" TEXT NOT NULL UNIQUE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "reviews" ADD CONSTRAINT "fk_reviews_business_id" FOREIGN KEY ("business_id") REFERENCES "businesses" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "reviews" ADD CONSTRAINT "fk_reviews_author_id" FOREIGN KEY ("author_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "review_photos" ADD CONSTRAINT "fk_review_photos_review_id" FOREIGN KEY ("review_id") REFERENCES "reviews" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "review_votes" ADD CONSTRAINT "fk_review_votes_review_id" FOREIGN KEY ("review_id") REFERENCES "reviews" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "review_votes" ADD CONSTRAINT "fk_review_votes_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "owner_replies" ADD CONSTRAINT "fk_owner_replies_review_id" FOREIGN KEY ("review_id") REFERENCES "reviews" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;More Social & community templates
- Social networkProfiles, follows, posts with media, comments and likes.
- Discussion forumCategories, threads and posts with reactions and moderation reports.
- Chat / messagingDirect and group conversations, messages, attachments and read receipts.
- Dating appProfiles with photos, swipes, mutual matches, messages and blocks.
- Meetup groupsInterest groups with members, events at venues and RSVPs.
- Q&A siteQuestions, answers with votes, accepted answers and tags.
- Creator membershipsCreators offering paid tiers, supporters' pledges and members-only posts.
- GamificationPoints ledger, levels, badges and streaks for an engaged community.
- Mentorship programmeProgrammes matching mentors with mentees, sessions and feedback.
- Chat app (Firestore)Users, rooms with their members, and messages as a subcollection of each room.
- Activity feed (Cassandra)Each user's feed by time bucket, follower lists both ways, and like counters.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.