database-api-design
Skill0 starsChanged 38 days agoMITView on GitHub
Designs and changes PostgreSQL schemas (Prisma, Supabase, SQL migrations) and API contracts without losing data or breaking existing clients, covering constraints, indexes, zero-downtime expand/contract migrations, row level security, soft delete, response DTOs, pagination and backward compatibility. Use when adding or altering tables, columns, indexes or policies, when writing or reviewing a migration, or when adding, renaming or removing fields in an API request or response.
In this repository7 other files it gives its agents.
- templates/AGENTS.mdAGENTS.md
- backend-engineeringSkill
- deployment-readinessSkill
- frontend-engineeringSkill
- production-deliverySkill
- security-auditSkill
- testing-qaSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Read the current schema, the migration history, and the code that reads and writes the affected tables.
- Distinctive: line 19
Ask what the queries are. Indexes, denormalization and pagination strategy follow from access patterns, not from the entity diagram.
- Distinctive: line 31
Every migration ships with an answer to "how do we get back": a down migration, a compensating migration, or a clear statement that it is …
≈ “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.
Files
Database and API design
Schema and contract changes differ from other code changes in one way that matters: existing data and existing clients do not change when you deploy. A migration runs against rows that were written under the old rules, and an API response is read by code that was built against the old shape. Design each change so both survive it.
Before changing a schema
- Read the current schema, the migration history, and the code that reads and writes the affected tables. If the ORM models, the database and the TypeScript types disagree, find out which is true before adding to the confusion.
- Work out which database a command will touch before running it. Look at the host in the connection configuration without printing credentials. If it might be shared or production, do not run anything against it; write the migration and hand over the command.
- Ask what the queries are. Indexes, denormalization and pagination strategy follow from access patterns, not from the entity diagram.
Designing
Let the database enforce what must always be true: NOT NULL, foreign keys with a deliberate ON DELETE, unique constraints for "only one of these", check constraints for ranges and states. Application checks alone lose to concurrent requests and to the next script someone runs by hand.
Details that are easy to get wrong in this stack (money and BigInt serialization, timestamps, soft delete with unique constraints, RLS on new tables, Prisma's handling of renames) are in references/schema-and-contract-notes.md. Read it when designing tables or response shapes.
Migrating
Any change that removes or reinterprets something existing code depends on is done in stages: add the new thing, make code work with both, move the data, then remove the old thing in a later release. Renames, type changes, new NOT NULL columns and dropped columns all follow this pattern. Step-by-step recipes, including lock-safe index and constraint creation on large tables, are in references/migration-playbook.md. Read it before writing any migration that is more than adding a nullable column or a new table.
Every migration ships with an answer to "how do we get back": a down migration, a compensating migration, or a clear statement that it is irreversible and what backup covers it.
Stop and ask first
Get explicit approval, with the plan and the risk stated, before:
- running any migration against a database that is not a disposable local or test instance;
- any step that drops or rewrites data (drop column or table, type change, backfill that overwrites);
- a breaking change to a published API field;
- resetting a database or editing migration history.
Writing the migration file and showing it is always fine. Applying it is the user's call.
API contracts
Treat a published response or request shape as something other code is compiled against. Additive, optional changes are safe; everything else needs a transition (new field alongside old, or a new version) and a search for consumers first. Return explicit, selected fields so that a column added to a table tomorrow does not leak through an endpoint written today.
Reporting
Say what changed in the schema and contract, which existing rows and clients are affected, what was run and against which database, how to roll back, and which steps of a staged migration are still pending for a later release.
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
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.

