Effect CommunityEC
Effect Community9mo ago
12 replies
Matheus

Handling Migrations with Drizzle and Effect/SQL for MySQL

How to deal with migrations using mysql, drizzle migrator and effect/sql? Basically I'm creating a mysql container whenever I run the tests and trying to migrate using the 'migrator' package from drizzle

import { MysqlDrizzle } from '@effect/sql-drizzle/Mysql'
import { beforeAll } from '@effect/vitest'
import { migrate } from 'drizzle-orm/mysql-proxy/migrator'
import { Console, Effect } from 'effect'
import { DatabaseTest } from './database-test'

beforeAll(async () => {
  await Effect.runPromise(
    Effect.gen(function* () {
      yield* Console.log('Running migrations...')
      const db = yield* MysqlDrizzle

      yield* Effect.promise(async () => {
        await migrate(
          db,
          async (queries) => {
            for (const query of queries) {
              await db.execute(query)
            }
          },
          {
            migrationsFolder: '../../database/migrations'
          }
        )
      })

       yield* Console.log('Migrations completed')
    }).pipe(Effect.provide(DatabaseTest))
  ).catch((error) => console.error(error))
})


And I'm getting the error
(FiberFailure) TypeError: Cannot read properties of undefined (reading 'insertId')

I've tried to run the migrations reading the files and executing with the SqlClient but no success yet.
Was this page helpful?