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