database-migrations
Database migration patterns and schema versioning
Works with
---
name: database-migrations
description: Database migration patterns and schema versioning
license: MIT
---
# Database Migration Patterns
Manage database schema changes safely and reliably.
## Migration File Structure
```
migrations/
001_create_users.sql
002_add_email_index.sql
003_create_orders.sql
```
## Writing Safe Migrations
### Adding Columns
```sql
-- migrations/004_add_user_status.sql
-- Up
ALTER TABLE users ADD COLUMN status VARCHAR(20) DEFAULT 'active';
CREATE INDEX idx_users_status ON users(status);
-- Down
DROP INDEX idx_users_status;
ALTER TABLE users DROP COLUMN status;
```
### Creating Tables
```sql
-- migrations/005_create_audit_log.sql
-- Up
CREATE TABLE audit_log (
id SERIAL PRIMARY KEY,
table_name VARCHAR(100) NOT NULL,
record_id INTEGER NOT NULL,
action VARCHAR(20) NOT NULL,
changed_by INTEGER REFERENCES users(id),
changed_at TIMESTAMP DEFAULT NOW(),
old_values JSONB,
new_values JSONB
);
CREATE INDEX idx_audit_log_table ON audit_log(table_name, record_id);
CREATE INDEX idx_audit_log_time ON audit_log(changed_at);
-- Down
DROP TABLE audit_log;
```
## Best Practices
1. Always include rollback (down) migrations
2. Never modify existing migrations - create new ones
3. Test migrations on a copy of production data
4. Use transactions for atomic changes
5. Add indexes concurrently in production: `CREATE INDEX CONCURRENTLY`More Database skills
supabase-postgres-best-practices
supabase/agent-skills
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pg_cron, pgmq), vector/semantic search (pgvector), and restoring dumps (pg_restore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.
prisma-database-setup
prisma/skills
Guides for configuring Prisma with different database providers (PostgreSQL, MySQL, SQLite, MongoDB, etc.). Use when setting up a new project, changing databases, or troubleshooting connection issues. Triggers on "configure postgres", "connect to mysql", "setup mongodb", "sqlite setup".
prisma-postgres
prisma/skills
Prisma Postgres setup and operations guidance across Console, create-db CLI, Management API, and Management API SDK. Use when creating Prisma Postgres databases, working in Prisma Console, provisioning with create-db/create-pg/create-postgres, or integrating programmatic provisioning with service tokens or OAuth.

