Skip to content
Data and runtime

PostgreSQL AGENTS.md

Database edits are where an agent can do damage with one statement. This file tells it to change schema with an additive migration, to parameterize every value, and to run statements against the local database named in the project's env example.

Paste, then edit

Destructive SQL, including DROP, a column rename, and a delete without a where clause, waits for a person.

In this stack

What to tell the agent

Do

  • Name the migration tool (Drizzle, Atlas, Flyway, a SQL directory).
  • Say whether indexes are created concurrently in production.
  • Tell the agent which role it may use locally.
  • Ask it to include the rollback note in the pull request when a change is not trivially additive.

Leave alone

  • Running DROP TABLE, TRUNCATE, or a column drop.
  • Disabling a constraint to make a load succeed.
  • Copying production connection strings into the instruction file or the chat summary.
Starter file

AGENTS.md to copy

Save this as AGENTS.md at the root of the repository, or next to the package it covers. Replace the commands with the ones in this repo. See which agents read the file.

AGENTS.md
# PostgreSQL

## Schema
- Change the schema with a new migration. Do not edit a migration that has already shipped.
- Prefer an additive change: a new column with a default or null, a new table, a new index.
- A drop, a rename, or a type change that rewrites a table needs a person to approve it first.

## Queries
- Pass values as parameters. Do not concatenate user input into SQL.
- Select the columns you need. Avoid select * in code that maps rows to a type.
- A delete or update has a where clause. Show the clause in the summary.

## Where it runs
- Use the local database URL from the env example. Refuse a URL whose host is not localhost unless a person pasted it for this task.
- Do not point a migration at production.

## Checks
- Apply the migration to the local database with the project's command.
- Run the test that covers the query you changed.
- In the report, paste the migration filename and the command you ran.
Commands to confirm

Checks named in the file

Confirm each command exists here before you rely on it. Delete the ones this repository does not use.

  • Apply local migrations. pnpm db:migrate
  • Open a local shell. psql "$DATABASE_URL"
FAQ

Questions

What is the PostgreSQL AGENTS.md for?

It keeps a Postgres agent on additive migrations and the local database, and it requires a person for destructive SQL.

Which schema changes can an agent make without asking?

Additive ones: a new table, a new nullable column, a new index, a new migration file. Dropping or renaming something people already query waits for a person, because the application and the database have to move together.

How does the file keep an agent off the production database?

It names the local URL from the env example and tells the agent to refuse any other host. Production credentials stay out of the instruction file.

Keep going

Related on MCPpedia