Fix DB issue 2s
This commit is contained in:
@@ -21,7 +21,7 @@ if shared_path not in sys.path:
|
||||
sys.path.insert(0, shared_path)
|
||||
|
||||
try:
|
||||
from app.core.config import settings
|
||||
from app.config import AlertProcessorConfig
|
||||
from shared.database.base import Base
|
||||
|
||||
# Import all models to ensure they are registered with Base.metadata
|
||||
@@ -36,7 +36,8 @@ except ImportError as e:
|
||||
config = context.config
|
||||
|
||||
# Set database URL from environment variables or settings
|
||||
database_url = os.getenv('DATABASE_URL')
|
||||
# Try service-specific DATABASE_URL first, then fall back to generic
|
||||
database_url = os.getenv('ALERT_PROCESSOR_DATABASE_URL') or os.getenv('DATABASE_URL')
|
||||
|
||||
# If DATABASE_URL is not set, construct from individual components
|
||||
if not database_url:
|
||||
@@ -49,11 +50,22 @@ if not database_url:
|
||||
if all([postgres_host, postgres_db, postgres_user, postgres_password]):
|
||||
database_url = f"postgresql+asyncpg://{postgres_user}:{postgres_password}@{postgres_host}:{postgres_port}/{postgres_db}"
|
||||
else:
|
||||
# Fallback to settings
|
||||
database_url = getattr(settings, 'DATABASE_URL', None)
|
||||
# As a last resort, construct the database URL manually from individual environment variables
|
||||
# that are likely to be set in the Kubernetes environment
|
||||
db_user = os.getenv("ALERT_PROCESSOR_DB_USER", "alert_processor_user")
|
||||
db_password = os.getenv("ALERT_PROCESSOR_DB_PASSWORD", "alert_processor_pass123")
|
||||
db_host = os.getenv("ALERT_PROCESSOR_DB_HOST", "alert-processor-db-service")
|
||||
db_port = os.getenv("ALERT_PROCESSOR_DB_PORT", "5432")
|
||||
db_name = os.getenv("ALERT_PROCESSOR_DB_NAME", "alert_processor_db")
|
||||
|
||||
database_url = f"postgresql+asyncpg://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
|
||||
|
||||
if database_url:
|
||||
print(f"Using database URL: {database_url}")
|
||||
config.set_main_option("sqlalchemy.url", database_url)
|
||||
else:
|
||||
print("ERROR: No database URL configured!")
|
||||
raise Exception("No database URL found after all fallback methods")
|
||||
|
||||
# Interpret the config file for Python logging
|
||||
if config.config_file_name is not None:
|
||||
|
||||
Reference in New Issue
Block a user