Automatic Database Migrations
@nuxthub/core >= v0.8.0
.We're excited to introduce automatic database migrations in NuxtHub.
Automatic Migration Application
SQL migrations in server/database/migrations/*.sql
are automatically applied when you:
- Start the development server (
npx nuxt dev
ornpx nuxt dev --remote
) - Preview builds locally (
npx nuxthub preview
) - Deploy via
npx nuxthub deploy
or Cloudflare Pages CI
Starting now, when you clone any of our templates with a database, all migrations apply automatically!
→ Deploy the Todo App template
New CLI Commands
[email protected]
introduces these database migration commands:
# 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
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:
- 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
- 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.