Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

zyvor migrate

Two modes: generate a SQL file, or apply migrations to a database.

Generate only

zyvor migrate                                  # .zyvor/schema.zyvor → migrations/0001_initial.sql
zyvor migrate path/to/schema.zyvor             # custom schema
zyvor migrate schema.zyvor out/custom.sql      # custom output

Output directories are created as needed. Existing output files are overwritten.

Apply

zyvor migrate --apply
zyvor migrate --apply --database postgres://user:pass@localhost/mydb

This is the mode you’ll use daily. It:

  1. resolves the database URL
  2. creates the database if it doesn’t exist
  3. ensures _zyvor_migrations exists
  4. scans migrations/*.sql, sorts by filename
  5. for each file: checksum → skip / drift-error / apply + record
  6. lists the resulting tables
🚀 Applying migrations to database...
   Database: postgres://postgres:****@localhost/my_app
📦 Creating database 'my_app'...
✅ Database 'my_app' created!
📋 Found 2 migration file(s)

⏭️  0001_initial.sql already applied. Skipping.
📝 Applying: 0002_schema_update.sql
✅ 0002_schema_update.sql applied successfully!

Tables in database:
  📋 _zyvor_migrations
  📋 posts
  📋 users

Passwords are always masked in output.

Where the URL comes from

Highest priority first:

  1. --database <URL>
  2. DATABASE_URL environment variable
  3. .zyvor/.env
  4. .zyvor/config.toml → [database] url

If none is found, you get an actionable error telling you exactly what to create.

Two errors you’ll actually see

No migration files

No migration files found in .zyvor/migrations/. Run 'zyvor dev' first.

dev generates the files. Run it before applying.

Schema drift

❌ Schema drift in '0001_initial.sql'! Checksum mismatch.
Old: 4a2f...
New: 9c1b...

You edited a migration that was already applied. Don’t do that — migrations are history. Write a new forward migration instead. If you’re intentionally resetting a dev database, drop it and re-apply from scratch.

Not available yet

migrate status, migrate reset, migrate dev, and rollback. To undo something today, write a new migration that reverses it.