Feature flags database schema
Flags per environment, targeting rules and per-user overrides.
5 tables, 4 relationships
Opens as a new diagram you can change. Free.
Tables
environments
- iduuid not null
- nametext not null
- created_attimestamptz not null
flags
- iduuid not null
- keytext not null
- descriptiontext
- archivedboolean not null
- created_attimestamptz not null
flag_states
- iduuid not null
- flag_id> flagsuuid not null
- environment_id> environmentsuuid not null
- enabledboolean not null
- rollout_percentinteger not null
- created_attimestamptz not null
flag_rules
- iduuid not null
- flag_state_id> flag_statesuuid not null
- attributetext not null
- operatortext not null
- valuetext not null
- priorityinteger not null
- created_attimestamptz not null
flag_overrides
- iduuid not null
- flag_state_id> flag_statesuuid not null
- subject_keytext not null
- enabledboolean 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 "environments" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL UNIQUE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "flag_overrides" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"flag_state_id" UUID NOT NULL,
"subject_key" TEXT NOT NULL,
"enabled" BOOLEAN NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "flag_rules" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"flag_state_id" UUID NOT NULL,
"attribute" TEXT NOT NULL,
"operator" TEXT NOT NULL,
"value" TEXT NOT NULL,
"priority" INTEGER DEFAULT 0 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "flag_states" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"flag_id" UUID NOT NULL,
"environment_id" UUID NOT NULL,
"enabled" BOOLEAN DEFAULT false NOT NULL,
"rollout_percent" INTEGER DEFAULT 0 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "flags" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"key" TEXT NOT NULL UNIQUE,
"description" TEXT,
"archived" BOOLEAN DEFAULT false NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "flag_states" ADD CONSTRAINT "fk_flag_states_flag_id" FOREIGN KEY ("flag_id") REFERENCES "flags" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "flag_states" ADD CONSTRAINT "fk_flag_states_environment_id" FOREIGN KEY ("environment_id") REFERENCES "environments" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "flag_rules" ADD CONSTRAINT "fk_flag_rules_flag_state_id" FOREIGN KEY ("flag_state_id") REFERENCES "flag_states" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "flag_overrides" ADD CONSTRAINT "fk_flag_overrides_flag_state_id" FOREIGN KEY ("flag_state_id") REFERENCES "flag_states" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;More SaaS & accounts templates
- SaaS starterOrganisations, users and memberships for a multi-tenant app.
- Authentication & sessionsUsers with linked identities, sessions, password resets and MFA factors.
- Roles & permissionsRole-based access control: roles, permissions and who holds them.
- Subscription billingCustomers, plans and prices, subscriptions, invoices and payments.
- Usage-based billingMeters, usage events and rate cards that roll up into invoices.
- Audit logWho did what to which record, with before and after values.
- NotificationsNotification types, per-user preferences, an inbox and delivery attempts.
- API platformDeveloper apps with API keys, webhooks and usage records.
- Product analyticsUsers, sessions and tracked events with properties, plus saved funnels.
- Sessions and rate limits (DynamoDB)Sign-in sessions and per-key request counters, each removed by DynamoDB's TTL when it lapses.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.