Automatic Database Migrations

Database migrations now automatically apply during development and deployment.
This feature is available on both free and pro plans starting with @nuxthub/core >= v0.8.0.

We're excited to introduce automatic database migrations in NuxtHub.

Automatic Database Migrations

Automatic Migration Application

SQL migrations in server/database/migrations/*.sql are automatically applied when you:

Starting now, when you clone any of our templates with a database, all migrations apply automatically!

→ Deploy the Todo App template

Database Migrations applied during deployment
Learn more about database migrations in our full documentation.

New CLI Commands

[email protected] introduces these database migration commands:

Terminal
# Create a new migration
npx nuxthub database migrations create <name>

# View migration status
npx nuxthub database migrations list

# Mark all migrations as applied
npx nuxthub database migrations mark-all-applied

Learn more about:

Migrating from Existing ORMs

Current Drizzle ORM users: Follow these specific migration steps.

Since NuxtHub doesn't recognize previously applied Drizzle ORM migrations (stored in __drizzle_migrations), it will attempt to rerun all migrations in server/database/migrations/*.sql. To prevent this:

  1. Mark existing migrations as applied in each environment:
    Terminal
    # Local environment
    npx nuxthub database migrations mark-all-applied
    
    # Preview environment
    npx nuxthub database migrations mark-all-applied --preview
    
    # Production environment
    npx nuxthub database migrations mark-all-applied --production
    
  2. Remove server/plugins/database.ts as it's no longer needed.

That's it! You can keep using npx drizzle-kit generate to generate migrations when updating your Drizzle ORM schema.

Understanding Database Migrations

Database migrations provide version control for your database schema. They track changes and ensure consistent schema evolution across all environments through incremental updates.

Start with NuxtHub today