/** * Drizzle ORM Migrator for postgres.do * * This module provides migration support for Drizzle ORM with postgres.do. * It uses Drizzle's built-in migration system to apply schema changes. * * @example * ```typescript * import { drizzle } from 'postgres.do/drizzle' * import { migrate } from 'postgres.do/drizzle/migrator' * import postgres from 'postgres.do' * * const sql = postgres('postgres://db.postgres.do/mydb') * const db = drizzle(sql) * * // Run migrations * await migrate(db, { migrationsFolder: './drizzle' }) * ``` */ import { readMigrationFiles, type MigrationConfig } from 'drizzle-orm/migrator' import type { PostgresDoDatabase } from './driver.js' /** * Run database migrations * * This function applies all pending migrations to the database. * It reads migration files from the specified folder and executes * them in order. * * @param db - The Drizzle database instance * @param config - Migration configuration * * @example * ```typescript * import { migrate } from 'postgres.do/drizzle/migrator' * * await migrate(db, { * migrationsFolder: './drizzle', * migrationsTable: '__drizzle_migrations', // optional * }) * ``` */ export async function migrate>( db: PostgresDoDatabase, config: MigrationConfig ): Promise { const migrations = readMigrationFiles(config) // @ts-expect-error - accessing internal dialect and session await db.dialect.migrate(migrations, db._.session, config) }