Initial commit - production deployment
This commit is contained in:
0
services/distribution/app/core/__init__.py
Normal file
0
services/distribution/app/core/__init__.py
Normal file
43
services/distribution/app/core/config.py
Normal file
43
services/distribution/app/core/config.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
Distribution Service Configuration
|
||||
"""
|
||||
|
||||
from shared.config.base import BaseServiceSettings
|
||||
from pydantic import Field
|
||||
from typing import Optional
|
||||
import os
|
||||
|
||||
|
||||
class Settings(BaseServiceSettings):
|
||||
"""
|
||||
Distribution Service specific settings
|
||||
"""
|
||||
|
||||
# Service Identity
|
||||
APP_NAME: str = "Distribution Service"
|
||||
SERVICE_NAME: str = "distribution-service"
|
||||
DESCRIPTION: str = "Distribution and logistics service for enterprise tier bakery management"
|
||||
VERSION: str = "1.0.0"
|
||||
|
||||
# Database Configuration
|
||||
# Use environment variables with fallbacks for development
|
||||
DB_HOST: str = os.getenv("DISTRIBUTION_DB_HOST", os.getenv("DB_HOST", "localhost"))
|
||||
DB_PORT: int = int(os.getenv("DISTRIBUTION_DB_PORT", os.getenv("DB_PORT", "5432")))
|
||||
DB_USER: str = os.getenv("DISTRIBUTION_DB_USER", os.getenv("DB_USER", "postgres"))
|
||||
DB_PASSWORD: str = os.getenv("DISTRIBUTION_DB_PASSWORD", os.getenv("DB_PASSWORD", "postgres"))
|
||||
DB_NAME: str = os.getenv("DISTRIBUTION_DB_NAME", os.getenv("DB_NAME", "distribution_db"))
|
||||
|
||||
@property
|
||||
def DATABASE_URL(self) -> str:
|
||||
"""Build database URL from components"""
|
||||
# Try service-specific environment variable first
|
||||
env_url = os.getenv("DISTRIBUTION_DATABASE_URL") or os.getenv("DATABASE_URL")
|
||||
if env_url:
|
||||
return env_url
|
||||
|
||||
# Build from components
|
||||
return f"postgresql+asyncpg://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"
|
||||
|
||||
|
||||
# Create settings instance
|
||||
settings = Settings()
|
||||
17
services/distribution/app/core/database.py
Normal file
17
services/distribution/app/core/database.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Distribution Service Database Configuration
|
||||
"""
|
||||
|
||||
from shared.database import DatabaseManager, create_database_manager
|
||||
from .config import settings
|
||||
import os
|
||||
|
||||
|
||||
# Create database manager instance
|
||||
database_manager = create_database_manager(settings.DATABASE_URL, service_name="distribution")
|
||||
|
||||
# Convenience function to get database sessions
|
||||
async def get_db():
|
||||
"""Get database session generator"""
|
||||
async with database_manager.get_session() as session:
|
||||
yield session
|
||||
Reference in New Issue
Block a user