The entire database has been changed to PostgresSQL. The entire code has been updated.
This commit is contained in:
24
database/__init__.py
Normal file
24
database/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import logging.config
|
||||
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine, AsyncSession
|
||||
|
||||
from database.models import Base
|
||||
|
||||
from config import DATABASE_URL
|
||||
from logger_helper.logger_helper import LOGGING_CONFIG
|
||||
|
||||
logging.config.dictConfig(LOGGING_CONFIG)
|
||||
logger = logging.getLogger("database")
|
||||
|
||||
async_engine = create_async_engine(DATABASE_URL, echo=False)
|
||||
|
||||
async_session = async_sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
|
||||
async def init_db():
|
||||
try:
|
||||
async with async_engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
logger.info("Database initialized.")
|
||||
except Exception as e:
|
||||
logger.error("Database initialization failed: %s", e)
|
Reference in New Issue
Block a user