Update database path configuration to use absolute path
- Updated alembic.ini to use absolute SQLite path - Ensured DB_DIR creation in config settings - Removed duplicate directory creation code generated with BackendIM... (backend.im)
This commit is contained in:
parent
5b55eedd2b
commit
61c5a0945a
@ -35,6 +35,7 @@ script_location = alembic
|
||||
# are written from script.py.mako
|
||||
# output_encoding = utf-8
|
||||
|
||||
# sqlalchemy.url is now set dynamically in env.py
|
||||
sqlalchemy.url = sqlite:////app/storage/db/db.sqlite
|
||||
|
||||
# Logging configuration
|
||||
|
@ -1,4 +1,9 @@
|
||||
from logging.config import fileConfig
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the parent directory to sys.path
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
@ -12,6 +17,9 @@ from app.db.base import Base
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Override sqlalchemy.url with the value from settings
|
||||
config.set_main_option("sqlalchemy.url", settings.SQLALCHEMY_DATABASE_URL)
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name is not None:
|
||||
|
@ -20,7 +20,9 @@ class Settings(BaseSettings):
|
||||
|
||||
# Database settings
|
||||
DB_DIR: Path = Path("/app") / "storage" / "db"
|
||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
DB_PATH: Path = DB_DIR / "db.sqlite"
|
||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_PATH}"
|
||||
|
||||
# Password reset settings
|
||||
PASSWORD_RESET_TOKEN_EXPIRE_HOURS: int = 24
|
||||
@ -40,6 +42,3 @@ class Settings(BaseSettings):
|
||||
|
||||
# Create the settings object
|
||||
settings = Settings()
|
||||
|
||||
# Ensure the database directory exists
|
||||
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
|
Loading…
x
Reference in New Issue
Block a user