© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago
Braveheart

Performing Drizzle ORM migration in vitest results in permission errors

In a test i'm using Drizzle ORM to do migrations in vitest beforeAll, but it doesn't work like when I run a script from

    "db:migrate": "tsx db/migrate.ts", //runs with no issues
    "db:migrate": "tsx db/migrate.ts", //runs with no issues

which then calls this

import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import { db } from './db'

import { fileURLToPath } from 'url'
import { dirname, join } from 'path'

export const migrateWrapper = async () => {
    await migrate(db, { migrationsFolder: migrationsPath }) // does the actual migration
}
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import { db } from './db'

import { fileURLToPath } from 'url'
import { dirname, join } from 'path'

export const migrateWrapper = async () => {
    await migrate(db, { migrationsFolder: migrationsPath }) // does the actual migration
}

but when running in a test file I get root cause error:

// console.log('yearly-recurring-events.test.ts')
beforeAll(async () => {
  await resetDatabase() //includes the migration call
  await seedRecurringEvents()
})
// console.log('yearly-recurring-events.test.ts')
beforeAll(async () => {
  await resetDatabase() //includes the migration call
  await seedRecurringEvents()
})


Caused by: SqliteError: disk I/O error
 ❯ PreparedQuery.run node_modules/.pnpm/drizzle-orm@0.29.2_@types+react@18.2.45_better-sqlite3@9.2.2_expo-sqlite@13.2.0_react@18.2.0/node_modules/src/better-sqlite3/session.ts:103:20
 ❯ BetterSQLiteSession.run node_modules/.pnpm/drizzle-orm@0.29.2_@types+react@18.2.45_better-sqlite3@9.2.2_expo-sqlite@13.2.0_react@18.2.0/node_modules/src/sqlite-core/session.ts:140:67
 ❯ SQLiteSyncDialect.migrate node_modules/.pnpm/drizzle-orm@0.29.2_@types+react@18.2.45_better-sqlite3@9.2.2_expo-sqlite@13.2.0_react@18.2.0/node_modules/src/sqlite-core/dialect.ts:721:11
 .
.
Caused by: SqliteError: disk I/O error
 ❯ PreparedQuery.run node_modules/.pnpm/drizzle-orm@0.29.2_@types+react@18.2.45_better-sqlite3@9.2.2_expo-sqlite@13.2.0_react@18.2.0/node_modules/src/better-sqlite3/session.ts:103:20
 ❯ BetterSQLiteSession.run node_modules/.pnpm/drizzle-orm@0.29.2_@types+react@18.2.45_better-sqlite3@9.2.2_expo-sqlite@13.2.0_react@18.2.0/node_modules/src/sqlite-core/session.ts:140:67
 ❯ SQLiteSyncDialect.migrate node_modules/.pnpm/drizzle-orm@0.29.2_@types+react@18.2.45_better-sqlite3@9.2.2_expo-sqlite@13.2.0_react@18.2.0/node_modules/src/sqlite-core/dialect.ts:721:11
 .
.


and then results in

Migrating the database...

stderr | Module.migrateWrapper (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/db/migrateUtil.ts:19:13)
Failed to migrate the database: DrizzleError: Failed to run the query '
                        CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
                                id SERIAL PRIMARY KEY,
                                hash text NOT NULL,
                                created_at numeric
                        )
                '
Migrating the database...

stderr | Module.migrateWrapper (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/db/migrateUtil.ts:19:13)
Failed to migrate the database: DrizzleError: Failed to run the query '
                        CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
                                id SERIAL PRIMARY KEY,
                                hash text NOT NULL,
                                created_at numeric
                        )
                '
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

truncate table in drizzle-orm
Drizzle TeamDTDrizzle Team / help
2y ago
Self-Relation in Drizzle ORM?
Drizzle TeamDTDrizzle Team / help
2y ago
Drizzle ORM issues
Drizzle TeamDTDrizzle Team / help
15mo ago
Need Help: `ilike` Function Not Returning Expected Results in Drizzle ORM
Drizzle TeamDTDrizzle Team / help
2y ago