Fix database path and migration engine configuration to resolve connection errors
generated with BackendIM... (backend.im)
This commit is contained in:
parent
fb94dd1153
commit
c196ff6cc8
@ -2,6 +2,7 @@ from logging.config import fileConfig
|
|||||||
|
|
||||||
from sqlalchemy import engine_from_config
|
from sqlalchemy import engine_from_config
|
||||||
from sqlalchemy import pool
|
from sqlalchemy import pool
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from alembic import context
|
from alembic import context
|
||||||
|
|
||||||
@ -63,13 +64,10 @@ def run_migrations_online() -> None:
|
|||||||
and associate a connection with the context.
|
and associate a connection with the context.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
connectable = engine_from_config(
|
# Import the engine directly from our app
|
||||||
config.get_section(config.config_ini_section, {}),
|
from app.db.database import engine
|
||||||
prefix="sqlalchemy.",
|
|
||||||
poolclass=pool.NullPool,
|
|
||||||
)
|
|
||||||
|
|
||||||
with connectable.connect() as connection:
|
with engine.connect() as connection:
|
||||||
context.configure(
|
context.configure(
|
||||||
connection=connection, target_metadata=target_metadata
|
connection=connection, target_metadata=target_metadata
|
||||||
)
|
)
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
# Get base project directory
|
||||||
|
PROJECT_DIR = Path("/projects/simpletodoapplication-222fyi")
|
||||||
|
|
||||||
# Create database directory if it doesn't exist
|
# Create database directory if it doesn't exist
|
||||||
DB_DIR = Path("/projects/simpletodoapplication-222fyi/app/storage/db")
|
DB_DIR = PROJECT_DIR / "app" / "storage" / "db"
|
||||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user