What Are Database Migrations? Schema Version Control
Database migrations version-control your schema changes. Learn how to use them safely with OpenClaw deployments.
Database migrations are scripts that describe how to evolve your database schema from one version to the next. Instead of manually running ALTER TABLE commands, you write migration files that describe the change, and a tool applies them in order.
How Migrations Work
- You modify your schema definition (e.g., add a
lastSeencolumn tousers) - The migration tool generates an
upscript (apply change) anddownscript (revert change) - Migrations run in order — each is idempotent or tracked as applied
- Your application code assumes the schema is up-to-date
Migration Tools by ORM
- Drizzle:
drizzle-kit generatecreates migration files from schema,drizzle-kit migrateapplies them - Prisma:
prisma migrate devgenerates and applies migrations - Raw SQL: tools like
db-migrate,flyway,liquibase
Running Migrations on Fly.io
For Drizzle (used by EZClaw):
pnpm db:generate # Create migration files from schema
pnpm db:migrate # Apply pending migrations
Run migrations in your CI/CD pipeline before deploying the new app version. If migrations run after deploy, there's a window where old code hits new schema.
Best Practices
Always make migrations backward-compatible (old code works with new schema) when possible. Use pnpm db:push for quick schema iteration in dev — it applies changes directly without migration files.