Performing Drizzle ORM migration in vitest results in permission errors

403 views Asked by At

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

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
}

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()
})
Caused by: SqliteError: disk I/O error
 ❯ PreparedQuery.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/better-sqlite3/session.ts:103:20
 ❯ BetterSQLiteSession.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/session.ts:140:67
 ❯ SQLiteSyncDialect.migrate node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/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
                        )
                '

repo: https://github.com/quantuminformation/drizzle-sqlite-recurring-events

0

There are 0 answers