agentleFS
charanjit-singhcharanjit-singh/lovable-skills/skills/supabase-database-design/SKILL.md

supabase-database-design

Skill10 starsChanged 6 months agoMITView on GitHub

Use when designing Supabase/Postgres schemas: new tables, relationships, indexes, enums, constraints, or normalizing data models. Not for RLS policies only (use supabase-rls-and-auth) or client hooks (use typed-api-hooks-forms).

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every FK explicit: project_id uuid not null references public.projects(id) on delete cascade.

    line 20
  2. Distinctive:

    Avoid over-indexing low-cardinality booleans alone.

    line 37
  3. Very specific:

    After schema changes: supabase gen types typescript → app uses Database types.

    line 56
  4. Distinctive:

    Keep types in source control so reviewers see schema drift in PRs.

    line 58

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Supabase database design

Table conventions

  • id uuid primary key default gen_random_uuid() (or bigint for high-volume internal).
  • created_at timestamptz not null default now()
  • updated_at timestamptz — maintain via trigger or app on update.
  • Snake_case table/column names; plural table names (projects, comments).

Relationships

  • Every FK explicit: project_id uuid not null references public.projects(id) on delete cascade.
  • Choose on delete: cascade (owned children), restrict (prevent orphaning), set null (optional link).
  • Junction tables for many-to-many: project_members(project_id, user_id, role).

Indexes

Add indexes for:

  • FK columns used in joins/filters (project_id, user_id).
  • Common filters: where status = ?, order by created_at desc.
  • Unique business keys: slug, stripe_customer_id.
create index posts_project_id_created_at_idx
  on public.posts (project_id, created_at desc);

Avoid over-indexing low-cardinality booleans alone.

Enums vs lookup tables

  • Few fixed values, rare changes → create type post_status as enum (...).
  • User-defined or admin-editable labels → statuses lookup table.

Constraints

  • not null on required fields; check for ranges (amount_cents >= 0).
  • unique (organization_id, slug) for scoped uniqueness.

Money and time

  • Money: bigint cents (amount_cents), not numeric or float. Currency in a separate column.
  • Time: always timestamptz, never timestamp (timezone-naive). Store UTC; format in UI.

Types and codegen

After schema changes: supabase gen types typescript → app uses Database types.

Keep types in source control so reviewers see schema drift in PRs.

Avoid

  • JSON blobs for relational data you query/filter often.
  • Missing FKs with “logical” IDs only in app code.
  • user_id as text instead of uuid references auth.users.

Checklist

  • PK + timestamps on every table
  • FKs + indexes on filter/join columns
  • Migration file named and ordered (migration-playbook)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.