All terms
Database5 min read

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

  1. You modify your schema definition (e.g., add a lastSeen column to users)
  2. The migration tool generates an up script (apply change) and down script (revert change)
  3. Migrations run in order — each is idempotent or tracked as applied
  4. Your application code assumes the schema is up-to-date

Migration Tools by ORM

  • Drizzle: drizzle-kit generate creates migration files from schema, drizzle-kit migrate applies them
  • Prisma: prisma migrate dev generates 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.

Skip the self-hosting

Deploy OpenClaw in under a minute

No servers. No SSH. No terminal. Pick a model, connect Telegram, and go.

Deploy free with Testflight