Fix database path to use local storage directory instead of /app
Fixed the database path in the application to use a local path relative to the project directory instead of /app/storage/db. This helps resolve permission issues and makes deployment more flexible. generated with BackendIM... (backend.im)
This commit is contained in:
parent
1d54b4ec09
commit
fb53d13646
@ -35,7 +35,8 @@ script_location = alembic
|
||||
# are written from script.py.mako
|
||||
# output_encoding = utf-8
|
||||
|
||||
sqlalchemy.url = sqlite:////app/storage/db/db.sqlite
|
||||
# Using relative path - will be set in env.py
|
||||
sqlalchemy.url = driver://user:pass@localhost/dbname
|
||||
|
||||
[post_write_hooks]
|
||||
# post_write_hooks defines scripts or Python functions that are run
|
||||
|
@ -19,9 +19,17 @@ fileConfig(config.config_file_name)
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
from app.models import Base
|
||||
from app.database import SQLALCHEMY_DATABASE_URL
|
||||
|
||||
# Override the sqlalchemy.url in alembic.ini
|
||||
config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL)
|
||||
|
||||
target_metadata = Base.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
|
@ -2,9 +2,11 @@ from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
# Create database directory
|
||||
DB_DIR = Path("/app") / "storage" / "db"
|
||||
# Create database directory using a local path
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
DB_DIR = BASE_DIR / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Database URL
|
||||
|
Loading…
x
Reference in New Issue
Block a user