Ensured alembic path has proper root
This commit is contained in:
parent
046583371d
commit
0b8a59edcb
|
|
@ -1,6 +1,6 @@
|
|||
[alembic]
|
||||
script_location = alembic
|
||||
prepend_sys_path = .
|
||||
prepend_sys_path = . ..
|
||||
|
||||
[loggers]
|
||||
keys = root,sqlalchemy,alembic
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from logging.config import fileConfig
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from alembic import context
|
||||
|
||||
# Ensure project_code root is in sys.path so 'backend.app' can be imported anywhere
|
||||
backend_dir = Path(__file__).resolve().parents[1]
|
||||
code_root = backend_dir.parent
|
||||
if str(code_root) not in sys.path:
|
||||
sys.path.insert(0, str(code_root))
|
||||
if str(backend_dir) not in sys.path:
|
||||
sys.path.insert(0, str(backend_dir))
|
||||
|
||||
# Alembic Config object
|
||||
config = context.config
|
||||
|
||||
|
|
@ -12,7 +22,7 @@ if config.config_file_name is not None:
|
|||
|
||||
# Import models target metadata
|
||||
from backend.app.models.user import Base
|
||||
target_metadata = Base.metadata
|
||||
target_metadata = Base.metadata if Base is not None else None
|
||||
|
||||
def get_url():
|
||||
return os.getenv(
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ try:
|
|||
|
||||
except ImportError:
|
||||
# Lightweight fallback model when SQLAlchemy is not loaded in current environment
|
||||
Base = None
|
||||
class User:
|
||||
def __init__(self, subject: str, email: str, full_name: Optional[str] = None,
|
||||
is_active: bool = True, id: Optional[str] = None):
|
||||
|
|
|
|||
Loading…
Reference in New Issue