Some checks failed
API Endpoint Tests / test-api-endpoints (push) Waiting to run
CLI Tests / test-cli (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Documentation Validation / validate-docs (push) Has been cancelled
- Updated marketplace commands: `marketplace --action` → `market` subcommands - Updated wallet commands: direct flags → `wallet` subcommands - Updated AI commands: `ai-submit`, `ai-status` → `ai submit`, `ai status` - Updated blockchain commands: `chain` → `blockchain info` - Standardized command structure across all workflow files - Affected files: MULTI_NODE_MASTER_INDEX.md, TEST_MASTER_INDEX.md, multi-node-blockchain-marketplace
40 lines
1.3 KiB
Python
Executable File
40 lines
1.3 KiB
Python
Executable File
"""Database configuration for the coordinator API."""
|
|
|
|
from sqlalchemy import StaticPool
|
|
from sqlmodel import SQLModel, create_engine
|
|
|
|
from .config import settings
|
|
|
|
# Create database engine using URL from config with performance optimizations
|
|
if settings.database_url.startswith("sqlite"):
|
|
engine = create_engine(
|
|
settings.database_url,
|
|
connect_args={
|
|
"check_same_thread": False,
|
|
"timeout": 30
|
|
},
|
|
poolclass=StaticPool,
|
|
echo=settings.test_mode, # Enable SQL logging for debugging in test mode
|
|
pool_pre_ping=True, # Verify connections before using
|
|
)
|
|
else:
|
|
# PostgreSQL/MySQL with connection pooling
|
|
engine = create_engine(
|
|
settings.database_url,
|
|
pool_size=10, # Number of connections to maintain
|
|
max_overflow=20, # Additional connections when pool is exhausted
|
|
pool_pre_ping=True, # Verify connections before using
|
|
pool_recycle=3600, # Recycle connections after 1 hour
|
|
echo=settings.test_mode, # Enable SQL logging for debugging in test mode
|
|
)
|
|
|
|
|
|
def create_db_and_tables():
|
|
"""Create database and tables"""
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
|
|
async def init_db():
|
|
"""Initialize database by creating tables"""
|
|
create_db_and_tables()
|