Enforce Rollback Steps in Database Migrations
Requires every database migration to include a down or rollback step, so a bad deploy can be reversed without writing SQL by hand under pressure.
What it flags
import type { Knex } from 'knex';
// No down(): a failed deploy cannot roll this schema back
export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('invoices', (table) => {
table.date('due_date');
table.string('payment_terms', 20).notNullable().defaultTo('net_30');
});
await knex.schema.createTable('invoice_reminders', (table) => {
table.increments('id');
table.integer('invoice_id').notNullable().references('invoices.id').index();
table.timestamp('sent_at').notNullable();
});
}import type { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('invoices', (table) => {
table.date('due_date');
table.string('payment_terms', 20).notNullable().defaultTo('net_30');
});
await knex.schema.createTable('invoice_reminders', (table) => {
table.increments('id');
table.integer('invoice_id').notNullable().references('invoices.id').index();
table.timestamp('sent_at').notNullable();
});
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTable('invoice_reminders');
await knex.schema.alterTable('invoices', (table) => {
table.dropColumn('payment_terms');
table.dropColumn('due_date');
});
}Why it matters
When a deploy goes wrong, the fastest recovery is often rolling back the code, and the schema may need to go back with it. A migration without a down step leaves the on-call engineer writing reversal SQL by hand, against production, during an incident. Writing the rollback at review time also exposes changes that cannot be reversed cleanly, such as dropped columns or lossy type changes, while there is still time to plan for them.
Agent instructions
cubic checks every pull request against these instructions. Paste them into AGENTS.md or Cursor rules and your AI coding tool follows them while it writes code.
AGENTS.md
Add this section to AGENTS.md at the repository root. Codex, Cursor, and other AI coding tools read it.
## Enforce Rollback Steps in Database Migrations Each database migration file must include a "down" or "rollback" section that reverses the changes. This ensures all database changes can be safely undone if deployment issues occur. Migration files should clearly separate "up" and "down" migrations using appropriate method names or comments.
Checks every changed file.
Related agents
Included in the Django, Ruby on Rails, and PostgreSQL code review standards.
Run this agent on every pull request
cubic reviews every pull request against the agents you turn on and comments on the lines that break them.