IMigration, registered with @decorator.migration(). The decorator adds the class to the container and to the migrations registry, so the runner can resolve and order it. up() applies the change and down() reverses it.
Scaffold a migration
Generate a timestamped migration class with the CLI.talos migration:create writes a migration class under modules/<module>/src/migrations/, a matching test under modules/<module>/tests/migrations/, refreshes the migrations.ts barrel export, and creates the module’s bin/migration/up.ts and bin/migration/down.ts runners if they are missing.
| Option | Description | Default |
|---|---|---|
--module | Target module the migration is generated into. | shared |
--name option. The generated class is a ready-to-fill stub:
migration:create command for the full reference.
Implement up() and down()
Fill in up() with the schema change and down() with its exact reverse. Both receive the transaction (tx) the runner wraps around the migration and the pooled sql client:
Order with dependencies
The runner sorts migrations by version, but a migration’s dependencies always run first regardless of timestamp. Declare them ingetDependencies() when one change must precede another:
Migrations that hold up
Makedown() the exact reverse of up(): drop precisely what up adds, since an asymmetric or irreversible down() is a bug. Once a migration has run on a shared database, never edit it — add a new corrective migration instead of rewriting one that already ran.
Add indexes for foreign keys, WHERE and ORDER BY columns, and unique constraints in up(), then drop them in down() before the table or column they cover. Keep column types, nullability, and lengths in sync with the entity definition, so a non-nullable column is also NOT NULL in the migration.
Next steps
- Running migrations: apply pending migrations with
talos migration:up. - Rolling back: reverse a migration with
talos migration:down.