agentleFS
imbhargav5imbhargav5/nextbase-nextjs-supabase-starter/.agents/skills/supabase-schema-migrations/SKILL.md

supabase-schema-migrations

Skill827 starsChanged 3 months agoMITView on GitHub

Use for any NextBase Supabase schema, RLS, function, trigger, enum, index, extension, generated database type, or migration change and enforce this repository's schema-first generated-migration workflow.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    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
  • could be automatic: a setting could enforce it
  1. Very specific:

    Never manually create migration files in apps/database/supabase/migrations.

    line 12
  2. Distinctive:

    Never manually edit generated migration files.

    line 13
  3. Distinctive:

    Never paste hand-written SQL directly into a migration file.

    line 14
  4. Distinctive:

    Read generated migrations for review only.

    line 16
  5. Very specific:

    Start the local stack from the root with pnpm database#start.

    line 22
  6. Distinctive:

    If it is wrong, fix the declarative schema, discard only the newly generated migration, and generate it again.

    line 25
  7. Distinctive:

    Run the relevant lint, typecheck, test, and build commands for consumers.

    line 28
  8. Distinctive:

    Add behavioral pgTap coverage for authorization changes.

    line 41

≈ “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 Schema Migrations

Load the vendored supabase and supabase-postgres-best-practices skills. Current Supabase documentation and the installed CLI are authoritative for command flags.

Hard Boundary

  • Never manually create migration files in apps/database/supabase/migrations.
  • Never manually edit generated migration files.
  • Never paste hand-written SQL directly into a migration file.
  • Make schema changes first in apps/database/supabase/schemas/*.sql.
  • Read generated migrations for review only. If generated SQL is wrong, fix the declarative schema and regenerate.

Schema-First Workflow

  1. Inspect neighboring files in apps/database/supabase/schemas and the existing migration history.
  2. Edit or add the appropriate declarative schema file. Keep stable object ordering to reduce diff churn.
  3. Start the local stack from the root with pnpm database#start.
  4. From apps/database, generate the migration with pnpm supabase db diff -f <descriptive_name>.
  5. Review the generated SQL for accidental drops, policy churn, missing grants, destructive conversions, ordering problems, and unrelated changes.
  6. If it is wrong, fix the declarative schema, discard only the newly generated migration, and generate it again. Do not patch generated SQL.
  7. Apply and validate the local schema as appropriate, then run pnpm --dir apps/database test-db.
  8. From the root, run pnpm gen-types-local. The only generated TypeScript destination is apps/web/src/lib/database.types.ts.
  9. Run the relevant lint, typecheck, test, and build commands for consumers.

RLS and Security Review

For every exposed table or function, verify:

  • RLS is enabled and forced where the design requires it.
  • USING and WITH CHECK cover every intended role and operation.
  • Ownership derives from auth.uid() or another trusted server value.
  • Foreign keys used by policies and common joins have appropriate indexes.
  • Functions use deliberate invoker/definer semantics, a safe search_path, and explicit execute grants.
  • Grants and schema exposure do not broaden access unintentionally.

Add behavioral pgTap coverage for authorization changes; policy-name assertions alone are insufficient.

Diff Limitations

Some operations are not represented safely by schema diff. If the desired change cannot be expressed by this workflow, stop and explain the limitation. Do not work around it by hand-authoring or editing a migration unless the repository rule itself is explicitly changed.

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.