tux.cli.database
¶
Database commands for the Tux CLI.
Functions:
Name | Description |
---|---|
upgrade | Apply all pending migrations (alembic upgrade head). |
downgrade | Downgrade one migration step (alembic downgrade -1). |
revision | Create a new migration autogenerating from model changes. |
current | Show current migration revision. |
history | Show migration history. |
Functions¶
_run_alembic_command(args: list[str], env: dict[str, str]) -> int
¶
Run an Alembic command with the provided environment variables.
Source code in tux/cli/database.py
Python
def _run_alembic_command(args: list[str], env: dict[str, str]) -> int:
"""Run an Alembic command with the provided environment variables."""
logger.info(f"Using database URL: {env['DATABASE_URL']}")
env_vars = os.environ | env
try:
logger.info("Running: alembic %s", " ".join(args))
return run_command(["alembic", *args], env=env_vars)
except Exception as exc:
logger.error("Error running alembic command: %s", exc)
return 1
upgrade() -> int
¶
Apply all pending migrations (alembic upgrade head).
downgrade() -> int
¶
Downgrade one migration step (alembic downgrade -1).
revision() -> int
¶
Create a new migration autogenerating from model changes.