simpletodoapp-ayt143/test_migrations.py

55 lines
1.9 KiB
Python

"""
Test script to verify that Alembic migrations will work in the container environment.
"""
import os
import sys
from pathlib import Path
print(f"Current working directory: {os.getcwd()}")
print(f"Initial Python path: {sys.path}")
# Simulate the container environment where alembic is executed
repo_dir = Path('/app/repo')
if not repo_dir.exists():
print(f"Simulating the /app/repo directory structure (not found on disk)")
# Just for testing, we'll use the current directory
repo_dir = Path(os.getcwd())
# Get paths for important files
alembic_dir = repo_dir / 'alembic'
env_py = alembic_dir / 'env.py'
find_modules_py = alembic_dir / 'find_modules.py'
print(f"Alembic directory: {alembic_dir}")
print(f"env.py exists: {env_py.exists()}")
print(f"find_modules.py exists: {find_modules_py.exists()}")
# Add alembic directory to Python path
if str(alembic_dir) not in sys.path:
sys.path.insert(0, str(alembic_dir))
print(f"Added alembic directory to sys.path: {sys.path}")
# Try to import our module
try:
from find_modules import setup_python_path
print(f"Successfully imported setup_python_path from find_modules")
# Try to set up the Python path
paths = setup_python_path()
print(f"Updated Python path: {paths}")
# Try to import our models
try:
from app.models import Todo
print(f"Successfully imported Todo model: {Todo}")
from app.core.database import Base
print(f"Successfully imported Base from database module: {Base}")
print("Migration imports should work correctly!")
except ImportError as e:
print(f"Error importing app modules: {e}")
print("You may need to run this script from the project root directory.")
except ImportError as e:
print(f"Error importing find_modules: {e}")
print("Make sure you're running this script from the project root directory.")