- Updated docker-compose.yml to allow disabling embedded Ollama via environment variable. - Refactored Dockerfile and Dockerfile.dev for improved dependency management and installation process. - Enhanced FastAPI migration scripts to handle orphaned Alembic revisions and added new database migration logic. - Improved error handling in background tasks and Codex authentication endpoints. - Added support for font file uploads with better validation and extraction of font names. - Introduced new image search functionality with support for Pexels and Pixabay APIs.
83 lines
3.1 KiB
Python
83 lines
3.1 KiB
Python
from collections.abc import AsyncGenerator
|
|
import os
|
|
from sqlalchemy.ext.asyncio import (
|
|
AsyncEngine,
|
|
create_async_engine,
|
|
async_sessionmaker,
|
|
AsyncSession,
|
|
)
|
|
from sqlmodel import SQLModel
|
|
|
|
from models.sql.async_presentation_generation_status import (
|
|
AsyncPresentationGenerationTaskModel,
|
|
)
|
|
from models.sql.image_asset import ImageAsset
|
|
from models.sql.key_value import KeyValueSqlModel
|
|
from models.sql.ollama_pull_status import OllamaPullStatus
|
|
from models.sql.presentation_layout_code import PresentationLayoutCodeModel
|
|
from models.sql.presentation import PresentationModel
|
|
from models.sql.template import TemplateModel
|
|
from models.sql.template_create_info import TemplateCreateInfoModel
|
|
from models.sql.slide import SlideModel
|
|
from models.sql.webhook_subscription import WebhookSubscription
|
|
from utils.db_utils import get_database_url_and_connect_args
|
|
from utils.get_env import get_app_data_directory_env
|
|
from utils.get_env import get_migrate_database_on_startup_env
|
|
|
|
|
|
database_url, connect_args = get_database_url_and_connect_args()
|
|
|
|
sql_engine: AsyncEngine = create_async_engine(database_url, connect_args=connect_args)
|
|
async_session_maker = async_sessionmaker(sql_engine, expire_on_commit=False)
|
|
|
|
|
|
async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
|
async with async_session_maker() as session:
|
|
yield session
|
|
|
|
|
|
# Container DB (Lives inside the app data directory)
|
|
_app_data_dir = get_app_data_directory_env() or "/tmp/presenton"
|
|
container_db_url = f"sqlite+aiosqlite:///{os.path.join(_app_data_dir, 'container.db')}"
|
|
container_db_engine: AsyncEngine = create_async_engine(
|
|
container_db_url, connect_args={"check_same_thread": False}
|
|
)
|
|
container_db_async_session_maker = async_sessionmaker(
|
|
container_db_engine, expire_on_commit=False
|
|
)
|
|
|
|
|
|
async def get_container_db_async_session() -> AsyncGenerator[AsyncSession, None]:
|
|
async with container_db_async_session_maker() as session:
|
|
yield session
|
|
|
|
|
|
# Create Database and Tables
|
|
async def create_db_and_tables():
|
|
should_run_alembic = get_migrate_database_on_startup_env() in ["true", "True"]
|
|
if not should_run_alembic:
|
|
async with sql_engine.begin() as conn:
|
|
await conn.run_sync(
|
|
lambda sync_conn: SQLModel.metadata.create_all(
|
|
sync_conn,
|
|
tables=[
|
|
PresentationModel.__table__,
|
|
SlideModel.__table__,
|
|
KeyValueSqlModel.__table__,
|
|
ImageAsset.__table__,
|
|
PresentationLayoutCodeModel.__table__,
|
|
TemplateCreateInfoModel.__table__,
|
|
TemplateModel.__table__,
|
|
WebhookSubscription.__table__,
|
|
AsyncPresentationGenerationTaskModel.__table__,
|
|
],
|
|
)
|
|
)
|
|
|
|
async with container_db_engine.begin() as conn:
|
|
await conn.run_sync(
|
|
lambda sync_conn: SQLModel.metadata.create_all(
|
|
sync_conn,
|
|
tables=[OllamaPullStatus.__table__],
|
|
)
|
|
)
|