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
|
# are written from script.py.mako
|
||||||
# output_encoding = utf-8
|
# output_encoding = utf-8
|
||||||
|
|
||||||
|
# sqlalchemy.url is now set dynamically in env.py
|
||||||
sqlalchemy.url = sqlite:////app/storage/db/db.sqlite
|
sqlalchemy.url = sqlite:////app/storage/db/db.sqlite
|
||||||
|
|
||||||
# Logging configuration
|
# Logging configuration
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
from logging.config import fileConfig
|
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 engine_from_config
|
||||||
from sqlalchemy import pool
|
from sqlalchemy import pool
|
||||||
@ -12,6 +17,9 @@ from app.db.base import Base
|
|||||||
# access to the values within the .ini file in use.
|
# access to the values within the .ini file in use.
|
||||||
config = context.config
|
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.
|
# Interpret the config file for Python logging.
|
||||||
# This line sets up loggers basically.
|
# This line sets up loggers basically.
|
||||||
if config.config_file_name is not None:
|
if config.config_file_name is not None:
|
||||||
|
@ -20,7 +20,9 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
# Database settings
|
# Database settings
|
||||||
DB_DIR: Path = Path("/app") / "storage" / "db"
|
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 settings
|
||||||
PASSWORD_RESET_TOKEN_EXPIRE_HOURS: int = 24
|
PASSWORD_RESET_TOKEN_EXPIRE_HOURS: int = 24
|
||||||
@ -39,7 +41,4 @@ class Settings(BaseSettings):
|
|||||||
case_sensitive = True
|
case_sensitive = True
|
||||||
|
|
||||||
# Create the settings object
|
# Create the settings object
|
||||||
settings = Settings()
|
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