Migrator
TypeExperimentalSignature
type Migrator<TMode> = {
migrateTo: (name) => ModeResult<TMode, MigrationResult>;
migrateToLatest: () => ModeResult<TMode, MigrationResult>;
};packages-internal/typed-sql/src/migrator.ts:94
Runs migrations, from createPgMigrator or createSqliteMigrator. Each call takes the
migration lease first, so many processes can migrate on boot at once: one migrates, the others
wait for it and then find nothing left to do. A migrator over a synchronous state provider, for
the adapters that support one, has TMode "sync": it takes no lease and returns its results
directly.
Type Parameters
- TModeextends
Modedefault"async"Whether the methods return promises or plain values.
Properties
migrateTo
Signature
migrateTo: (name) => ModeResult<TMode, MigrationResult>;packages-internal/typed-sql/src/migrator.ts:114
Bring the database to the migration named name: apply the pending migrations up to and
including it, or revert the applied migrations after it with their down, last first. With
null, revert every applied migration.
Parameters
- name
string|null
Returns
ModeResult<TMode,MigrationResult>
Throws
Error if name is not in the list, if a pending migration is listed before an
applied one, or, before reverting anything, if the database has applied migrations the code
doesn't know. Also if a migration's up or down fails, naming it, with the original error
as cause.
migrateToLatest
Signature
migrateToLatest: () => ModeResult<TMode, MigrationResult>;packages-internal/typed-sql/src/migrator.ts:103
Apply every pending migration, in list order. Applied migrations the code doesn't know are
reported in unrecognized and don't stop the run, so an older release keeps booting against a
database a newer one migrated.
Returns
ModeResult<TMode,MigrationResult>
Throws
Error if a pending migration is listed before an applied one, or if a migration
fails, naming it, with the original error as cause.