Improve console output for up/add down/drop commands.
public
Improve console output for up/add down/drop commands.
modified
src/mitch/cli/deploy.py
+8 −8
| @@ -95,8 +95,8 @@ |
| 95 | 95 | to_revert = list(repo.with_dependants(redeploy)) |
| 96 | 96 | runner.revert_migrations( |
| 97 | 97 | to_revert, |
| 98 | | - before_each=lambda migration: rich.print( |
| 99 | | - f"[blue]Reverting:[/blue] Migration '{migration.id}' due to modifications after deployment." |
| 98 | + before_each=lambda migration, status: rich.print( |
| 99 | + f"[blue]Reverting:[/blue] {status} migration '{migration.id}' due to modifications after deployment." |
| 100 | 100 | ), |
| 101 | 101 | ) |
| 102 | 102 | |
| @@ -105,8 +105,8 @@ |
| 105 | 105 | to_apply = list(repo.with_dependencies(pending | redeploy)) |
| 106 | 106 | runner.deploy_migrations( |
| 107 | 107 | to_apply, |
| 108 | | - before_each=lambda migration: rich.print( |
| 109 | | - f"[green]Deploying:[/green] Migration '{migration.id}'" |
| 108 | + before_each=lambda migration, status: rich.print( |
| 109 | + f"[green]Deploying:[/green] Migration '{migration.id}' ({status})" |
| 110 | 110 | ), |
| 111 | 111 | ) |
| 112 | 112 | |
| @@ -142,16 +142,16 @@ |
| 142 | 142 | to_revert = list(repo.with_dependants(applied_and_modified)) |
| 143 | 143 | runner.revert_migrations( |
| 144 | 144 | to_revert, |
| 145 | | - before_each=lambda migration: rich.print( |
| 146 | | - f"[blue]Reverted:[/blue] Migration '{migration.id}'" |
| 145 | + before_each=lambda migration, status: rich.print( |
| 146 | + f"[blue]Reverted:[/blue] Migration '{migration.id}' ({status})" |
| 147 | 147 | ), |
| 148 | 148 | ) |
| 149 | 149 | |
| 150 | 150 | to_be_applied = list(repo.with_dependencies(applied_and_modified | added_and_pending)) |
| 151 | 151 | runner.deploy_migrations( |
| 152 | 152 | to_be_applied, |
| 153 | | - before_each=lambda migration: rich.print( |
| 154 | | - f"[green]Deployed:[/green] Migration '{migration.id}'" |
| 153 | + before_each=lambda migration, status: rich.print( |
| 154 | + f"[green]Deployed:[/green] Migration '{migration.id}' ({status})" |
| 155 | 155 | ), |
| 156 | 156 | ) |
| 157 | 157 | |
modified
src/mitch/cli/revert.py
+2 −2
| @@ -42,7 +42,7 @@ |
| 42 | 42 | ) |
| 43 | 43 | runner.revert_migrations( |
| 44 | 44 | applied_migrations, |
| 45 | | - before_each=lambda migration: rich.print( |
| 46 | | - f"[blue]Reverting:[/blue] Migration '{migration.id}'" |
| 45 | + before_each=lambda migration, status: rich.print( |
| 46 | + f"[blue]Reverting:[/blue] Migration '{migration.id}' ({status})" |
| 47 | 47 | ), |
| 48 | 48 | ) |
modified
src/mitch/runner.py
+10 −4
| @@ -237,25 +237,31 @@ |
| 237 | 237 | def deploy_migrations( |
| 238 | 238 | self, |
| 239 | 239 | migrations: Iterable[Migration], |
| 240 | | - before_each: Callable[[Migration], None] | None = None, |
| 240 | + before_each: Callable[[Migration, str], None] | None = None, |
| 241 | 241 | ) -> None: |
| 242 | 242 | for batch in batch_transactional_migrations(migrations): |
| 243 | 243 | self.autocommit = not batch.transactional |
| 244 | 244 | with self.transaction() if batch.transactional else nullcontext(): |
| 245 | 245 | for migration in batch.migrations: |
| 246 | + status = self.deployment_status(migration) |
| 247 | + if status != "pending": |
| 248 | + continue |
| 246 | 249 | if before_each is not None: |
| 247 | | - before_each(migration) |
| 250 | + before_each(migration, status) |
| 248 | 251 | self.apply_migration(migration) |
| 249 | 252 | |
| 250 | 253 | def revert_migrations( |
| 251 | 254 | self, |
| 252 | 255 | migrations: Iterable[Migration], |
| 253 | | - before_each: Callable[[Migration], None] | None = None, |
| 256 | + before_each: Callable[[Migration, str], None] | None = None, |
| 254 | 257 | ) -> None: |
| 255 | 258 | for batch in batch_transactional_migrations(migrations): |
| 256 | 259 | self.autocommit = not batch.transactional |
| 257 | 260 | with self.transaction() if batch.transactional else nullcontext(): |
| 258 | 261 | for migration in batch.migrations: |
| 262 | + status = self.deployment_status(migration) |
| 263 | + if status not in ("applied", "modified"): |
| 264 | + continue |
| 259 | 265 | if before_each is not None: |
| 260 | | - before_each(migration) |
| 266 | + before_each(migration, status) |
| 261 | 267 | self.revert_migration(migration) |