editing deployment

This commit is contained in:
Flatlogic Bot 2026-01-29 02:38:23 +00:00
parent 04fa45e5f8
commit 212e4e71cc
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import time
from django.db import connections
from django.db.utils import OperationalError
from django.core.management.base import BaseCommand
class Command(BaseCommand):
"""Django command to pause execution until database is available"""
# Critical: Disable system checks to prevent the command from crashing
# if the database is not yet available.
requires_system_checks = []
def handle(self, *args, **options):
self.stdout.write('Waiting for database...')
db_conn = None
for i in range(30): # Retry for 30 seconds
try:
db_conn = connections['default']
# Try to actually connect
db_conn.cursor()
self.stdout.write(self.style.SUCCESS('Database available!'))
return
except OperationalError:
self.stdout.write('Database unavailable, waiting 1 second...')
time.sleep(1)
except Exception as e:
self.stdout.write(self.style.WARNING(f'Database error: {e}, waiting 1 second...'))
time.sleep(1)
self.stdout.write(self.style.ERROR('Database unavailable after 30 seconds.'))

13
entrypoint.sh Normal file → Executable file
View File

@ -3,6 +3,19 @@
# Exit immediately if a command exits with a non-zero status # Exit immediately if a command exits with a non-zero status
set -e set -e
echo "Starting deployment script..."
echo "Environment Verification:"
echo "DB_ENGINE: ${DB_ENGINE:-'Not Set (will default to settings.py)'}"
echo "DB_HOST: ${DB_HOST:-'Not Set'}"
echo "DB_PORT: ${DB_PORT:-'Not Set'}"
echo "DB_NAME: ${DB_NAME:-'Not Set'}"
echo "DB_USER: ${DB_USER:-'Not Set'}"
# Do NOT print DB_PASS
# Wait for database to be ready
echo "Checking database connection..."
python manage.py wait_for_db
# Apply database migrations # Apply database migrations
echo "Applying database migrations..." echo "Applying database migrations..."
python manage.py migrate python manage.py migrate