You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add use_logger parameter for migrations and include_driver_name for logging (#338)
Migration Logger Mode:
- Add `use_logger: bool = False` parameter to `migrate_up()` and `migrate_down()`
- When True, outputs to Python logger instead of Rich console
- Add `use_logger` field to `MigrationConfig` for persistent defaults
- Add `_resolve_use_logger()` helper to BaseMigrationCommands
- Method parameter overrides config default
Logging Config:
- Add `include_driver_name: bool = False` to `LoggingConfig`
- By default, sqlspec.driver is no longer in log output
- Users can opt-in with `LoggingConfig(include_driver_name=True)`
- OTel spans continue to include driver (unchanged)
- `db.system` always present to identify database type
- Extract helper functions for output routing (_output_info, _output_warning, _output_error, _output_exception)
- Extract helper methods for common operations:
- _collect_pending_migrations: collects migrations not yet applied
- _report_no_pending_migrations: handles "no migrations" output
- _apply_single_migration/_revert_single_migration: encapsulates migration execution
- _collect_revert_migrations: determines migrations to revert
- Use try/except/else pattern to satisfy TRY300 lint rule
- Format LoggingConfig __slots__ per ruff requirements
Update all upgrade and downgrade mock assertions to include the new
use_logger=False keyword argument that is now passed by the config
migration methods.
Copy file name to clipboardExpand all lines: sqlspec/config.py
+76-18Lines changed: 76 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,20 @@ class MigrationConfig(TypedDict):
151
151
transactional: NotRequired[bool]
152
152
"""Wrap migrations in transactions when supported. When enabled (default for adapters that support it), each migration runs in a transaction that is committed on success or rolled back on failure. This prevents partial migrations from leaving the database in an inconsistent state. Requires adapter support for transactional DDL. Defaults to True for PostgreSQL, SQLite, and DuckDB; False for MySQL, Oracle, and BigQuery. Individual migrations can override this with a '-- transactional: false' comment."""
153
153
154
+
use_logger: NotRequired[bool]
155
+
"""Use Python logger instead of Rich console for migration output.
156
+
157
+
When True, migration progress is logged via structlog/logging instead of being
158
+
printed to the console with Rich formatting. This is useful for programmatic
159
+
usage where console output is not desired (e.g., in tests, automated scripts,
160
+
or production deployments with structured logging).
161
+
162
+
Can be overridden per-call via the ``use_logger`` parameter on ``migrate_up()``
163
+
and ``migrate_down()`` methods.
164
+
165
+
Defaults to False (Rich console output).
166
+
"""
167
+
154
168
155
169
classFlaskConfig(TypedDict):
156
170
"""Configuration options for Flask SQLSpec extension.
0 commit comments