import { Kysely, Migration, MigrationProvider } from 'kysely' // Passes a context argument to migrations. We use this to thread the dialect into migrations export class CtxMigrationProvider implements MigrationProvider { constructor( private migrations: Record>, private ctx: T, ) {} async getMigrations(): Promise> { const ctxMigrations: Record = {} Object.entries(this.migrations).forEach(([name, migration]) => { ctxMigrations[name] = { up: async (db) => await migration.up(db, this.ctx), down: async (db) => await migration.down?.(db, this.ctx), } }) return ctxMigrations } } export interface CtxMigration { up(db: Kysely, ctx: T): Promise down?(db: Kysely, ctx: T): Promise }