Merge branch 'refactor/backend-architecture' into development

This commit is contained in:
yangshilin
2026-03-18 17:18:23 +08:00
parent 2070a03d35
commit 48b70e1350
266 changed files with 12386 additions and 9690 deletions

View File

@@ -6,7 +6,6 @@
python -m api.scripts.run_memoir_images_migration
"""
import json
import logging
import os
import sys
import uuid
@@ -14,34 +13,21 @@ import uuid
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
load_dotenv()
from sqlalchemy import text
from sqlalchemy import create_engine, text
from sqlalchemy.engine import Engine
from urllib.parse import urlsplit
logging.basicConfig(level=logging.INFO, format="%(message)s")
logger = logging.getLogger(__name__)
from app.core.config import settings
from app.core.db import ensure_psycopg_url
from app.core.logging import get_logger, setup_logging
setup_logging()
logger = get_logger(__name__)
def get_engine() -> Engine:
from sqlalchemy import create_engine
migration_url = os.getenv("MIGRATION_DATABASE_URL")
database_url = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@localhost:5432/life_echo")
url = migration_url or database_url
# region agent log
logger.info(
"DEBUG migration env selection: migration_present=%s database_present=%s selected=%s selected_host=%s migration_host=%s database_host=%s",
bool(migration_url),
bool(database_url),
"MIGRATION_DATABASE_URL" if migration_url else "DATABASE_URL",
urlsplit(url).hostname or "<missing-host>",
urlsplit(migration_url).hostname if migration_url else "<empty>",
urlsplit(database_url).hostname or "<missing-host>",
)
# endregion agent log
return create_engine(url.replace("postgresql://", "postgresql+psycopg://"), pool_pre_ping=True)
url = (settings.migration_database_url or "").strip() or settings.database_url
return create_engine(ensure_psycopg_url(url), pool_pre_ping=True)
def _row_from_image_json(img: dict | None, chapter_id: str, section_id: str | None, order_index: int) -> dict | None: