Gamification database schema
Points ledger, levels, badges and streaks for an engaged community.
6 tables, 4 relationships
Opens as a new diagram you can change. Free.
Tables
players
- iduuid not null
- usernametext not null
- created_attimestamptz not null
levels
- iduuid not null
- nametext not null
- min_pointsinteger not null
- created_attimestamptz not null
point_events
- iduuid not null
- player_id> playersuuid not null
- pointsinteger not null
- reasontext not null
- created_attimestamptz not null
badges
- iduuid not null
- keytext not null
- nametext not null
- descriptiontext not null
- created_attimestamptz not null
player_badges
- iduuid not null
- player_id> playersuuid not null
- badge_id> badgesuuid not null
- awarded_attimestamptz not null
- created_attimestamptz not null
streaks
- iduuid not null
- player_id> playersuuid not null
- currentinteger not null
- longestinteger not null
- last_active_ondate 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 "badges" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"key" TEXT NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "levels" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"min_points" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "player_badges" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"player_id" UUID NOT NULL,
"badge_id" UUID NOT NULL,
"awarded_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "players" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"username" TEXT NOT NULL UNIQUE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "point_events" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"player_id" UUID NOT NULL,
"points" INTEGER NOT NULL,
"reason" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "streaks" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"player_id" UUID NOT NULL UNIQUE,
"current" INTEGER DEFAULT 0 NOT NULL,
"longest" INTEGER DEFAULT 0 NOT NULL,
"last_active_on" DATE NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "point_events" ADD CONSTRAINT "fk_point_events_player_id" FOREIGN KEY ("player_id") REFERENCES "players" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "player_badges" ADD CONSTRAINT "fk_player_badges_player_id" FOREIGN KEY ("player_id") REFERENCES "players" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "player_badges" ADD CONSTRAINT "fk_player_badges_badge_id" FOREIGN KEY ("badge_id") REFERENCES "badges" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "streaks" ADD CONSTRAINT "fk_streaks_player_id" FOREIGN KEY ("player_id") REFERENCES "players" ("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.
- Reviews & ratingsBusinesses reviewed by users, with photos, helpful votes and owner replies.
- Creator membershipsCreators offering paid tiers, supporters' pledges and members-only posts.
- 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.