Migration behavior

Understand when ViteHub applies committed Drizzle and Prisma migrations during development and build.

ViteHub applies committed migrations for you, but it does not generate them. Keep migration authoring on the native ORM toolchain, then let ViteHub apply the committed files during development or build when you enable that behavior.

Commit the migration files you expect ViteHub to apply. ViteHub does not infer schema changes and does not generate new migrations at runtime.

When ViteHub runs migrations

Two shared flags control automatic application:

KeyPurpose
applyMigrationsDuringDevApplies committed migrations when the dev server starts.
applyMigrationsDuringBuildApplies committed migrations during build when the runtime supports it.

Set either flag to false when you want to run the migration step yourself.

nitro.config.ts
import { defineNitroConfig } from 'nitro/config'

export default defineNitroConfig({
  modules: ['@vitehub/db/nitro'],
  db: {
    orm: 'drizzle',
    dialect: 'sqlite',
    connection: {
      url: 'file:.data/db/app.sqlite',
    },
    applyMigrationsDuringDev: false,
    applyMigrationsDuringBuild: false,
  },
})

Drizzle migration flow

For Drizzle, ViteHub reads committed SQL migrations from db.drizzle.migrationsDirs and optional SQL files from db.drizzle.queriesPaths. It applies pending migrations first, then applies the configured query files.

nitro.config.ts
import { defineNitroConfig } from 'nitro/config'

export default defineNitroConfig({
  modules: ['@vitehub/db/nitro'],
  db: {
    orm: 'drizzle',
    dialect: 'sqlite',
    connection: {
      url: 'file:.data/db/app.sqlite',
    },
    drizzle: {
      migrationsDirs: ['server/db/migrations'],
      queriesPaths: ['server/db/queries/seed.sqlite.sql'],
    },
  },
})
Drizzle schema files do not replace committed migrations. If you want ViteHub to create tables automatically, add committed SQL migrations for those tables.

Prisma migration flow

For Prisma, ViteHub runs the deploy-style migration flow against the configured schema or prisma.config.ts. That keeps runtime behavior aligned with committed Prisma migrations instead of development-only schema pushes.

nitro.config.ts
import { defineNitroConfig } from 'nitro/config'

export default defineNitroConfig({
  modules: ['@vitehub/db/nitro'],
  db: {
    orm: 'prisma',
    dialect: 'postgresql',
    connection: {
      url: process.env.DATABASE_URL,
    },
    prisma: {
      schemaPath: 'prisma/schema.prisma',
      clientOutput: '.vitehub/db/prisma-client',
    },
  },
})

Generate migrations with native tools

Use the native ORM commands to author and review migrations before ViteHub applies them.

Terminal
pnpm drizzle-kit generate
pnpm drizzle-kit migrate
Keep automatic migration application enabled for local development and smoke builds, but review committed SQL or Prisma migrations before production deploys.