External DB init changes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# Docker entrypoint script for PPR API
|
||||
# Handles database migrations and data seeding automatically
|
||||
|
||||
set -e
|
||||
# Note: We don't use 'set -e' here because we need to handle specific exit codes from Python scripts
|
||||
|
||||
echo "========================================="
|
||||
echo "PPR API Container Starting"
|
||||
@@ -139,6 +139,30 @@ elif [ $DB_STATE -eq 0 ]; then
|
||||
else
|
||||
echo "✓ Database is up to date"
|
||||
fi
|
||||
|
||||
# Check if reference data needs to be loaded
|
||||
python3 << EOF
|
||||
from sqlalchemy import create_engine, text
|
||||
from app.core.config import settings
|
||||
|
||||
engine = create_engine(settings.database_url)
|
||||
with engine.connect() as conn:
|
||||
airport_count = conn.execute(text("SELECT COUNT(*) FROM airports")).fetchone()[0]
|
||||
aircraft_count = conn.execute(text("SELECT COUNT(*) FROM aircraft")).fetchone()[0]
|
||||
|
||||
if airport_count == 0 or aircraft_count == 0:
|
||||
print("Reference data missing - will load")
|
||||
exit(10)
|
||||
else:
|
||||
print(f"Reference data exists (airports: {airport_count}, aircraft: {aircraft_count})")
|
||||
exit(0)
|
||||
EOF
|
||||
|
||||
if [ $? -eq 10 ]; then
|
||||
echo "Loading reference data..."
|
||||
python3 /app/seed_data.py
|
||||
echo "✓ Reference data loaded"
|
||||
fi
|
||||
else
|
||||
echo "✗ Database check failed"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user