Fix database migration path issues for development environment
- Added proper path handling to alembic env.py - Updated database path to use relative paths in development - Created necessary storage directories - Updated alembic configuration to use dynamic SQLAlchemy URL generated with BackendIM... (backend.im)
This commit is contained in:
parent
d60cfb5c4f
commit
a9c71e9245
@ -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 a relative path with SQLite - will be replaced by env.py
|
||||
sqlalchemy.url = driver://user:pass@localhost/dbname
|
||||
|
||||
|
||||
[post_write_hooks]
|
||||
|
@ -1,14 +1,26 @@
|
||||
from logging.config import fileConfig
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
# Add the project root directory to Python's path
|
||||
BASE_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.append(str(BASE_DIR))
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Import the db session configuration
|
||||
from app.db.session import SQLALCHEMY_DATABASE_URL
|
||||
# Override the sqlalchemy.url with our dynamic configuration
|
||||
config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL)
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
|
@ -1,8 +1,11 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
DB_DIR = Path("/app") / "storage" / "db"
|
||||
# Use relative path for development environment
|
||||
BASE_DIR = Path(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
DB_DIR = BASE_DIR / "app" / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
|
Loading…
x
Reference in New Issue
Block a user