Fix database path issue to ensure write permissions
This commit is contained in:
parent
56e04ce623
commit
e263239cee
@ -1,11 +1,13 @@
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from pydantic import field_validator, BaseModel
|
||||
|
||||
# Get project root directory
|
||||
if '/app/repo' in str(Path.cwd()):
|
||||
# When running in the container
|
||||
ROOT_DIR = Path('/app/repo')
|
||||
# When running in the container, use a temporary directory
|
||||
# This ensures we have write permissions
|
||||
ROOT_DIR = Path(tempfile.gettempdir())
|
||||
else:
|
||||
# When running in development
|
||||
ROOT_DIR = Path(__file__).parent.parent.parent.resolve()
|
||||
|
@ -1,3 +1,4 @@
|
||||
import os
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
@ -7,6 +8,9 @@ from app.core.config import settings
|
||||
DB_DIR = settings.DB_DIR
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Ensure the database directory has write permissions
|
||||
os.chmod(DB_DIR, 0o777)
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = settings.SQLALCHEMY_DATABASE_URL
|
||||
|
||||
engine = create_engine(
|
||||
|
@ -1,5 +1,5 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
import os
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
from pathlib import Path
|
||||
@ -67,7 +67,11 @@ def run_migrations_online() -> None:
|
||||
|
||||
"""
|
||||
# Ensure the DB directory exists
|
||||
Path(settings.DB_DIR).mkdir(parents=True, exist_ok=True)
|
||||
db_dir = Path(settings.DB_DIR)
|
||||
db_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Ensure the database directory has write permissions
|
||||
os.chmod(db_dir, 0o777)
|
||||
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user