Create and manage database migrations for schema changes. Use when user needs to modify database schema, add tables, columns, indexes, or manage data migrations.
Create safe, reversible database migrations.
up needs a downBefore creating:
-- Up
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
-- Down
ALTER TABLE users DROP COLUMN phone;
-- Up
ALTER TABLE users ADD COLUMN status VARCHAR(20) DEFAULT 'active' NOT NULL;
-- Down
ALTER TABLE users DROP COLUMN status;
-- Step 1: Add new column
ALTER TABLE users ADD COLUMN full_name VARCHAR(255);
-- Step 2: Copy data (in application or separate migration)
UPDATE users SET full_name = name;
-- Step 3: (Later) Drop old column
ALTER TABLE users DROP COLUMN name;
-- PostgreSQL
CREATE INDEX CONCURRENTLY idx_users_email ON users(email);
db/migrate/ → Railsmigrations/ or alembic/ → Python/SQLAlchemyprisma/migrations/ → Prismadrizzle/ → DrizzleMatch the project's migration format and naming convention.