naman10parikh/acorn/design-multitenant-schema

Claude Code and agent skill by naman10parikh/acorn

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Design the schema / data model for a multi-tenant product. Use when the ask is "design a schema", "model this product's data", "what tables do we need", or "how should we structure the database for tenant X". Encodes acorn's tenancy decision tree + column house-style.

Install

npx vskill@latest install naman10parikh/acorn/design-multitenant-schema

SKILL.md

The same SKILL.md was published earlier as naman10parikh/acorn/design-multitenant-schema.

design-multitenant-schema

Brain source: brain/OPINIONS.md §Schema design + §Platform selection · brain/EXPERTISE-MAP.md JTBD 1 · brain/GAPS-AND-DISPUTES.md DISPUTE 1 (PK type). This skill is the runnable form of those stances — it states a default and names the dispute, it does not fake-resolve.

Trigger

The user (or a sibling agent) asks acorn to design / model the data layer of a multi-tenant product: "design a schema for a helpdesk", "model orgs → members → tickets", "what's the data model for this SaaS".

Steps

  1. Decide tenancy (the first decision — everything inherits it). Run the decision tree (src/gen/tenancy.ts):
  • shared-schema + `tenant_id` + RLS → the default for 10k–100k+ tenants (the model energy already uses). One schema, one migration, isolation enforced by RLS.
  • schema-per-tenant → only 10–500 high-value/customizable tenants (migrations fan out N times).
  • database-per-tenant → only a few regulated/data-residency tenants (connection pooling breaks immediately — PgBouncer pools are per (db,user)).
  • NEVER multi-tenant by table-prefix — even Convex abandoned it ("messy abstractions and performance bottlenecks"). State this if the user proposes it.
  1. Apply the column house-style on every tenant table:
  • PK: uuidv7() if the provider has shipped it (feature-detect — Supabase is still PG17, no native uuidv7) else gen_random_uuid() with a noted upgrade path. NEVER UUIDv4 on a high-insert table as a settled choice (it fragments the B-tree); the bigint-vs-uuidv7 split itself is open → name it, don't pretend.
  • Enum-like columns: text + CHECK (... IN (...)), NEVER native CREATE TYPE ... AS ENUM for anything that might change (you can't drop/reorder an enum value; also dodges drizzle-kit enum pain).
  • Variable-shape blobs: jsonb (binary, GIN-indexable), NEVER json — and don't reach for jsonb to dodge schema design.
  • `updated_at`: ONE shared moddatetime/trigger fn reused across tables (energy's bug: two duplicate-named ones).
  • Composite uniqueness: (tenant_id, natural_key) with tenant_id first in every composite index (so RLS predicates on it stay fast).
  1. Emit migrations + the gated RLS block for each tenant table (hand off to harden-rls).
  2. State the dispute, not a fake winner — if the PK type or RLS-depth is genuinely a coin-flip for this workload, say so and give the decision rule (brain/GAPS-AND-DISPUTES.md).

Output

A migration scaffold (CREATE TABLE statements with the house-style columns) + a one-paragraph tenancy decision with its rationale + a pointer to run harden-rls for the policies. The decision tree is also a pure function: decideTenancy({ tenants, regulated }) → { model, rationale, notes }.

Worked example

Ask: "Design a multi-tenant helpdesk: orgs have members; members file tickets; tickets have messages. ~10k orgs expected."

acorn's design:

  • Tenancy: ~10k tenants → shared-schema + `org_id` + RLS (decideTenancy({ tenants: 10000 }) → shared-schema-rls). Schema-per-tenant rejected (stops scaling past hundreds); DB-per-tenant rejected (no regulatory driver; pooling would break).
  • Tables (house-style):

``sql CREATE TABLE public.orgs ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), -- acorn: feature-detect uuidv7() at provision; gen_random_uuid() is the PG<18 fallback name text NOT NULL, plan text NOT NULL DEFAULT 'free' CHECK (plan IN ('free','pro','enterprise')), -- text+CHECK, not a PG enum created_at timestamptz NOT NULL DEFAULT now() ); CREATE TABLE public.tickets ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), org_id uuid NOT NULL REFERENCES public.orgs(id), subject text NOT NULL, status text NOT NULL DEFAULT 'open' CHECK (status IN ('open','pending','closed')), created_at timestamptz NOT NULL DEFAULT now() ); CREATE UNIQUE INDEX tickets_org_subject_idx ON public.tickets (org_id, subject); -- (tenant_id, natural_key), org_id first ``

  • Dispute named: for tickets (high write), bigint-identity would give marginally better locality than uuidv7 — but the global-id benefit + the agent-friendly opacity of uuidv7 wins here. acorn defaults uuidv7-when-available and flags the split rather than claiming it settled.
  • Next: run harden-rls to emit the gated 2-policy block on orgs/tickets/messages, then zero-downtime-migration to ship it safely.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/naman10parikh/acorn/design-multitenant-schema/badge)](https://verified-skill.com/skills/naman10parikh/acorn/design-multitenant-schema)

Something wrong with this skill or its page? Tell us.