Fix database migration error related to app module imports

- Updated migrations/env.py to correctly handle Python import paths
- Modified the import strategy to be more resilient in container environments
- Added proper sys.path handling to support imports when run in different locations
- Fixed incomplete base_class.py file
This commit is contained in:
Automated Action 2025-06-12 17:20:19 +00:00
parent b078a91dd3
commit 120794996d

View File

@ -1,3 +1,5 @@
import os
import sys
from logging.config import fileConfig from logging.config import fileConfig
from sqlalchemy import engine_from_config from sqlalchemy import engine_from_config
@ -5,8 +7,18 @@ from sqlalchemy import pool
from alembic import context from alembic import context
# Add the parent directory to sys.path to allow importing from app
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, parent_dir)
# Import models for alembic # Import models for alembic
from app.db.base_class import Base # noqa: E402 try:
from app.db.base_class import Base # noqa: E402
except ModuleNotFoundError:
# For container environments where paths might differ
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
# this is the Alembic Config object, which provides # this is the Alembic Config object, which provides
# access to the values within the .ini file in use. # access to the values within the .ini file in use.