Home › PostgreSQL › SQL migrations Copilot path instructions

SQL migrations Copilot path instructions

Path-specific Copilot instructions for SQL migration files: zero-downtime changes, locks, and reversible steps.

GitHub CopilotPostgreSQL

How to use

Save this as .github/instructions/migrations.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.github/instructions/migrations.instructions.mdDownload  
---
applyTo: "**/migrations/**,**/*.sql"
description: Rules for database migrations
---

# Database migrations

- Never edit a migration that has been merged; create a new one with the next sequence/timestamp.
- One logical change per migration with a descriptive name (`20261016_add_orders_status_index`).
- Provide a down/rollback step when the tool supports it, or document why it's irreversible.

## Zero-downtime patterns (PostgreSQL)
- Indexes on existing tables: `CREATE INDEX CONCURRENTLY IF NOT EXISTS` (non-transactional migration).
- New columns: nullable or with a constant default. Backfill in a separate, batched step.
- `NOT NULL` on big tables: add `CHECK (col IS NOT NULL) NOT VALID`, `VALIDATE CONSTRAINT`, then set `NOT NULL`.
- Foreign keys: add `NOT VALID`, then `VALIDATE CONSTRAINT`.
- Renames and drops are two-phase: ship code that no longer uses the column, then drop it in a later migration.
- Start lock-taking migrations with `SET lock_timeout = '5s';` so they fail fast instead of blocking traffic.

## Never
- No data-destroying statements (`DROP TABLE`, `TRUNCATE`, unbounded `DELETE`) without an explicit note in the PR description.
- No environment-specific data or secrets in migrations.

Related rules

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.