Goal
Protect database migration history and make schema changes safe for environments where previous migrations may already have been applied.
Repository Context
This production application uses PostgreSQL migrations.
Code exampleMarkdown
platform-api/
├── src/
├── migrations/
│ ├── 001_create_users.sql
│ ├── 002_create_organizations.sql
│ └── 003_add_memberships.sql
├── package.json
└── AGENTS.md
Committed migrations may already have been applied in staging or production.
The repository follows these rules:
- Previously applied migration files must not be rewritten to introduce new schema changes.
- New schema changes require a new migration.
- Migrations should be reviewed for compatibility with existing data.
- Destructive changes require an explicit migration strategy rather than assuming existing data can be discarded.
Current AGENTS.md
Code exampleMarkdown
# Project Instructions
## Database
- Keep migrations in `migrations/`.
- When the schema changes, edit the most recent migration so the migration history stays small.
- If an existing column is no longer needed, drop it immediately without considering existing data.
## Validation
- Run database tests after changing the schema.
Your Task
Repair the migration instructions.
Preserve previously applied migration history, require new migrations for new schema changes, and make destructive schema changes account for existing data.