Docs/API Reference/Database

Database API: migrations

The @veap/database/migrations subpath exports the migration generator, runner and schema builder.

1 min read

The @veap/database/migrations subpath exports the migration generator, runner and schema builder.

Migration contract#

ts
export interface Migration {
  name: string;
  up: (db: any, schema: Schema) => Promise<void>;
  down?: (db: any, schema: Schema) => Promise<void>;
}

runMigrations(scope, migrations) applies pending migration names for the supplied scope. rollbackMigrations(scope, migrations) rolls back the latest batch in reverse order when a migration with a matching down function is supplied.

Runner behavior#

The runner ensures a migrations table, tracks name, scope, batch and execution time, and wraps a batch in a transaction. It attempts a PostgreSQL advisory transaction lock. If the database has not been initialized, the runner returns without executing migrations; do not mistake that for a successful schema deployment.

Schema helpers#

The schema-builder module exports Schema, Blueprint, ColumnBuilder, sql and DatabaseDialect. Blueprint provides column helpers such as id, uuid, increments, text, varchar, string, integer, smallint, bigint, boolean, timestamp, timestamptz, timestamps, softDeletes, date, json, jsonb, bytea, blob and decimal. Check the installed source for the complete helper set and dialect-specific behavior.

Migration names are durable identifiers. Do not rename already-applied migrations casually; prefer a new forward migration.

veap
Preparing0%