Implementation:Promptfoo Promptfoo Database Migration
| Knowledge Sources | |
|---|---|
| Domains | Database, Migration |
| Last Updated | 2026-02-14 07:45 GMT |
Overview
Concrete tool for running Drizzle ORM database migrations on the SQLite database, creating the database if it does not exist.
Description
The Database_Migration module (migrate.ts) wraps Drizzle ORM's migrate() function to apply pending SQL migrations to the promptfoo SQLite database. It resolves the migrations folder path correctly across both development (source) and production (bundled) environments. The migration runs asynchronously via setImmediate to avoid blocking the event loop during startup. The module also supports direct execution (tsx src/migrate.ts) for manual migration runs.
Usage
Called during application startup to ensure the database schema is up to date. Can also be run directly as a standalone script.
Code Reference
Source Location
- Repository: Promptfoo_Promptfoo
- File: src/migrate.ts
- Lines: 1-122
Signature
export async function runDbMigrations(): Promise<void>
Import
import { runDbMigrations } from './migrate';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | — | — | Reads database path from config, migrations from filesystem |
Outputs
| Name | Type | Description |
|---|---|---|
| (void) | Promise<void> | Resolves when all pending migrations are applied |
Usage Examples
import { runDbMigrations } from './migrate';
// Run during application startup
await runDbMigrations();
# Run migrations directly
npx tsx src/migrate.ts
# Or via npm script
npm run db:migrate