chore: PostgreSQL migration compatibility and infrastructure improvements
Database & Migrations: - Update all Alembic migrations for PostgreSQL compatibility - Remove SQLite-specific syntax (AUTOINCREMENT, etc.) - Add database utility helpers for PostgreSQL operations - Fix services to use PostgreSQL-compatible queries Documentation: - Add comprehensive Docker deployment guide - Add production deployment documentation - Add infrastructure architecture documentation - Update database setup guide for PostgreSQL-only - Expand troubleshooting guide Architecture & Validation: - Add migration.yaml rules for SQL compatibility checking - Enhance validate_architecture.py with migration validation - Update architecture rules to validate Alembic migrations Development: - Fix duplicate install-all target in Makefile - Add Celery/Redis validation to install.py script - Add docker-compose.test.yml for CI testing - Add squash_migrations.py utility script - Update tests for PostgreSQL compatibility - Improve test fixtures in conftest.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
"""Database utilities for database operations.
|
||||
|
||||
This module provides utility functions and classes to interact with a database using SQLAlchemy. It includes:
|
||||
- Creating a database engine with connection pooling.
|
||||
- Creating a PostgreSQL database engine with connection pooling.
|
||||
- Generating a session factory for creating sessions.
|
||||
|
||||
Note: This project uses PostgreSQL only. SQLite is not supported.
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -16,31 +18,35 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_db_engine(database_url: str):
|
||||
"""Create a database engine with connection pooling.
|
||||
"""Create a PostgreSQL database engine with connection pooling.
|
||||
|
||||
Args:
|
||||
database_url (str): The URL string to connect to the database. It can be for SQLite or PostgreSQL databases.
|
||||
database_url (str): The PostgreSQL URL string to connect to the database.
|
||||
|
||||
Returns:
|
||||
sqlalchemy.engine.Engine: A SQLAlchemy Engine instance configured according to the provided database URL.
|
||||
sqlalchemy.engine.Engine: A SQLAlchemy Engine instance configured for PostgreSQL.
|
||||
|
||||
Raises:
|
||||
ValueError: If database_url is not a PostgreSQL URL.
|
||||
"""
|
||||
if database_url.startswith("sqlite"):
|
||||
# Configuration for SQLite database
|
||||
engine = create_engine(
|
||||
database_url, connect_args={"check_same_thread": False}, echo=False
|
||||
)
|
||||
else:
|
||||
# Configuration for PostgreSQL databases with connection pooling
|
||||
engine = create_engine(
|
||||
database_url,
|
||||
poolclass=QueuePool,
|
||||
pool_size=10,
|
||||
max_overflow=20,
|
||||
pool_pre_ping=True,
|
||||
echo=False,
|
||||
if not database_url.startswith("postgresql"):
|
||||
raise ValueError(
|
||||
f"Unsupported database: {database_url.split(':')[0]}. "
|
||||
"Only PostgreSQL is supported."
|
||||
)
|
||||
|
||||
logger.info(f"Database engine created for: {database_url.split('@')[0]}@...")
|
||||
engine = create_engine(
|
||||
database_url,
|
||||
poolclass=QueuePool,
|
||||
pool_size=10,
|
||||
max_overflow=20,
|
||||
pool_pre_ping=True,
|
||||
echo=False,
|
||||
)
|
||||
|
||||
# Log URL without password
|
||||
safe_url = database_url.split("@")[0] + "@..." if "@" in database_url else database_url
|
||||
logger.info(f"Database engine created for: {safe_url}")
|
||||
return engine
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user