CLI Commands
Cosmigrator parses the first CLI argument as a command. If no argument is provided, it defaults to migrate.
migrate
Applies all pending migrations in Id order.
dotnet run
# or explicitly:
dotnet run -- migrate
For each pending migration:
- Gets the target container via
migration.ContainerName - Calls
migration.UpAsync(container, client) - Records the migration in
__MigrationHistorywith statusApplied
Exits with code 0 on success, 1 on failure. If a migration fails, execution stops immediately — no further migrations are applied.
rollback
Undoes the last N applied migrations in reverse order.
# Roll back the last migration
dotnet run -- rollback
# Roll back the last 3 migrations
dotnet run -- rollback --steps 3
For each migration being rolled back:
- Finds the
IMigrationclass matching the history record - Calls
migration.DownAsync(container, client) - Updates the history record to status
RolledBack
If a migration class is not found in the assembly (e.g., deleted code), that rollback is skipped with a warning.
status
Prints the status of every discovered migration.
dotnet run -- status
Output shows each migration with its current status and timestamp:
[20250219_000001] AddEmailToUsers - Applied at 2025-02-19 14:30:00 UTC
[20250219_000002] RemoveMiddleName - Pending
Possible statuses: Applied, RolledBack, Pending.
list
Lists all discovered migration classes from the assembly.
dotnet run -- list
Output:
[20250219_000001] AddEmailToUsers -> Users
[20250219_000002] RemoveMiddleName -> Users
Total: 2 migration(s) discovered
Exit codes
| Code | Meaning |
|---|---|
0 | Success |
1 | Failure — a migration threw an exception, or an unknown command was used |