|
@@ -4,10 +4,19 @@ from sqlalchemy import Column, DateTime, Float, Integer, String, Text
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
from sqlalchemy.orm import declarative_base
|
|
from sqlalchemy.orm import declarative_base
|
|
|
|
|
|
|
|
|
|
+from pathlib import Path
|
|
|
|
|
+
|
|
|
from app.config import get_settings
|
|
from app.config import get_settings
|
|
|
|
|
|
|
|
settings = get_settings()
|
|
settings = get_settings()
|
|
|
|
|
|
|
|
|
|
+# 确保数据库目录存在
|
|
|
|
|
+db_path = settings.database_url.replace("sqlite+aiosqlite:///", "")
|
|
|
|
|
+if db_path.startswith("sqlite+aiosqlite:///"):
|
|
|
|
|
+ db_path = db_path.replace("sqlite+aiosqlite:///", "")
|
|
|
|
|
+if db_path and not db_path.startswith("memory"):
|
|
|
|
|
+ Path(db_path).parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+
|
|
|
Base = declarative_base()
|
|
Base = declarative_base()
|
|
|
|
|
|
|
|
engine = create_async_engine(
|
|
engine = create_async_engine(
|