Migration
TypeExperimentalSignature
type Migration<TTxContext, TMode> =
| TransactionalMigration<TTxContext, TMode>
| {
down: MigrationScript<TMode>;
name: string;
type: "non-transactional";
up: MigrationScript<TMode>;
};packages-internal/typed-sql/src/migrator.ts:49
One migration. Migrations run in the order of their list, and name identifies a migration in
the history table, so it must be unique and must not change once the migration has run.
up applies the migration and down reverts it when migrateTo targets an earlier migration.
A migration that cannot be reverted throws from its down: the revert stops there, and the
migration stays recorded.
transactional(the default):upanddownreceive the migration's transaction context and run inside that transaction, together with the history change, so your query builder works on the migration's connection.non-transactional:upanddownrun outside a transaction with their own database access (e.g.CREATE INDEX CONCURRENTLY, or a backfill in batches). CallassertLockHeldbetween steps of long work: it throws once the migration lease is lost. The history changes after the function resolves, so it must be safe to run again.
Type Parameters
- TTxContextThe state provider's transaction context.
- TModeextends
Modedefault"async"Whetherupanddownreturn promises or run synchronously.