database_setup ¶
Database setup service for bot initialization.
Classes:
-
DatabaseSetupService–Handles complete database initialization during bot setup.
Classes¶
DatabaseSetupService ¶
DatabaseSetupService(db_service: DatabaseService)
Bases: BaseSetupService
Handles complete database initialization during bot setup.
Initialize the database setup service.
Parameters:
-
db_service(DatabaseService) –The database service instance to use for connections.
Methods:
-
safe_setup–Execute setup with standardized error handling and tracing.
-
setup–Set up and validate the database connection and run migrations.
Functions¶
_find_project_root ¶
_find_project_root() -> Path
Find the project root by looking for alembic.ini.
Returns:
-
Path–The project root directory containing alembic.ini.
safe_setup async ¶
safe_setup() -> bool
Execute setup with standardized error handling and tracing.
Returns:
-
True if setup succeeded, False if it failed–
_build_alembic_config ¶
_build_alembic_config() -> Config
Build Alembic configuration with suppressed stdout output.
Returns:
-
Config–The configured Alembic Config object.
Notes
Most configuration is read from alembic.ini. Only the database URL is set programmatically as it comes from environment variables.
_log_step ¶
Log a setup step with consistent formatting.
_upgrade_head_if_needed async ¶
_upgrade_head_if_needed() -> None
Run Alembic upgrade to head on startup.
This call is idempotent and safe to run on startup. If database is unavailable, migrations are skipped with a warning. Runs migration synchronously with a short timeout.
Note
Unlike other setup steps, this method does not raise exceptions on failure. If migrations cannot run (e.g., database unavailable), it logs a warning and continues, allowing the bot to start without blocking on migrations.
setup async ¶
setup() -> None
Set up and validate the database connection and run migrations.
Raises:
-
TuxDatabaseConnectionError–If database connection or validation fails.
_validate_schema async ¶
_validate_schema() -> None
Validate that the database schema matches model definitions.