Skip to content

Commit

Permalink
fix: Update GitHub Actions workflow to fix Alembic module execution a…
Browse files Browse the repository at this point in the history
…nd add environment verification

- Use python -m alembic instead of direct alembic command
- Add Python environment verification before migrations
- Add database connection verification
- Add detailed debug output for troubleshooting
  • Loading branch information
devin-ai-integration[bot] committed Nov 10, 2024
1 parent 9a2ab3f commit 3d34d7c
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@ jobs:
# Initialize Alembic if not already initialized
if [ ! -f alembic.ini ]; then
alembic init migrations
python -m alembic init migrations
# Update alembic.ini with correct database URL
sed -i "s|sqlalchemy.url = .*|sqlalchemy.url = ${DATABASE_URL}|" alembic.ini
# Debug output
echo "Alembic initialization completed"
echo "Contents of alembic.ini:"
cat alembic.ini
fi
# Update env.py to use environment variable for database URL
Expand Down Expand Up @@ -207,11 +211,49 @@ jobs:
run_migrations_online()
EOL
# Create initial migration
alembic revision --autogenerate -m "Initial migration"
# Run migrations
alembic upgrade head
# Debug output before migrations
echo "Verifying migrations setup..."
ls -la migrations/
echo "Verifying migrations/versions directory..."
ls -la migrations/versions/
echo "Current working directory: $(pwd)"
# Verify Python environment
echo "Verifying Python environment..."
python << 'EOF'
import sys
import os
import site

print("Python version:", sys.version)
print("Python executable:", sys.executable)
print("PYTHONPATH:", os.getenv("PYTHONPATH"))
print("Site packages:", site.getsitepackages())
print("Working directory:", os.getcwd())
print("Environment variables:")
for key in ["DATABASE_URL", "PYTHONPATH"]:
print(f" {key}:", os.getenv(key))
EOF

# Verify database connection and environment
echo "Verifying database connection..."
python << 'EOF'
import os
import psycopg2
try:
conn = psycopg2.connect(os.getenv("DATABASE_URL"))
print("Database connection successful")
conn.close()
except Exception as e:
print(f"Database connection error: {e}")
exit(1)
EOF

echo "Running initial migration..."
python -m alembic revision --autogenerate -m "Initial migration"

echo "Running migration upgrade..."
python -m alembic upgrade head

- name: Run tests with coverage
working-directory: ./backend
Expand Down

0 comments on commit 3d34d7c

Please sign in to comment.