Fix: Use absolute path /app/data for SQLite in Docker
This commit is contained in:
@@ -21,13 +21,25 @@ class Base(DeclarativeBase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Async session factory
|
# Create data directory at module load time (before any engine connection)
|
||||||
async_engine = create_async_engine(DATABASE_URL, echo=False)
|
DATA_DIR = Path("/app/data")
|
||||||
|
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
# Async session factory - URL uses absolute path to /app/data
|
||||||
|
async_engine = create_async_engine(
|
||||||
|
f"sqlite+aiosqlite:///{DATA_DIR}/claudia_docs.db",
|
||||||
|
echo=False,
|
||||||
|
connect_args={"check_same_thread": False}
|
||||||
|
)
|
||||||
AsyncSessionLocal = async_sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False)
|
AsyncSessionLocal = async_sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False)
|
||||||
|
|
||||||
|
|
||||||
# Sync engine for migrations
|
# Sync engine for migrations
|
||||||
sync_engine = create_engine(SYNC_DATABASE_URL, echo=False)
|
sync_engine = create_engine(
|
||||||
|
f"sqlite:///{DATA_DIR}/claudia_docs.db",
|
||||||
|
echo=False,
|
||||||
|
connect_args={"check_same_thread": False}
|
||||||
|
)
|
||||||
SyncSessionLocal = sessionmaker(sync_engine)
|
SyncSessionLocal = sessionmaker(sync_engine)
|
||||||
|
|
||||||
|
|
||||||
@@ -51,8 +63,7 @@ async def get_db_simple():
|
|||||||
|
|
||||||
async def init_db():
|
async def init_db():
|
||||||
"""Initialize database with all tables, views, FTS5, and triggers."""
|
"""Initialize database with all tables, views, FTS5, and triggers."""
|
||||||
# Create data directory
|
# Data directory already created at module load time
|
||||||
Path("./data").mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
async with async_engine.begin() as conn:
|
async with async_engine.begin() as conn:
|
||||||
# Create all tables via SQL (not ORM) to handle SQLite-specific features
|
# Create all tables via SQL (not ORM) to handle SQLite-specific features
|
||||||
|
|||||||
Reference in New Issue
Block a user