83 lines
2.2 KiB
Bash
83 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
# Print environment variables for debugging
|
|
echo "Environment variables:"
|
|
echo "POSTGRES_USER: $POSTGRES_USER"
|
|
echo "POSTGRES_PASSWORD: $POSTGRES_PASSWORD"
|
|
echo "POSTGRES_DB: $POSTGRES_DB"
|
|
echo "DATABASE_URL: $DATABASE_URL"
|
|
|
|
# Wait for the database to be ready
|
|
echo "Waiting for database to be ready..."
|
|
while ! nc -z db 5432; do
|
|
sleep 0.1
|
|
done
|
|
echo "Database is ready!"
|
|
|
|
# Wait for PostgreSQL to be ready to accept connections
|
|
echo "Waiting for PostgreSQL to accept connections..."
|
|
until PGPASSWORD=$POSTGRES_PASSWORD psql -h db -U $POSTGRES_USER -d $POSTGRES_DB -c '\q'; do
|
|
echo "PostgreSQL is unavailable - sleeping"
|
|
sleep 1
|
|
done
|
|
echo "PostgreSQL is up - executing command"
|
|
|
|
# Clean up existing migrations and initialize fresh
|
|
echo "Cleaning up and initializing fresh migrations..."
|
|
rm -rf migrations/versions/*
|
|
flask db init
|
|
flask db migrate -m "Initial migration"
|
|
flask db upgrade
|
|
|
|
# Create events table
|
|
echo "Creating events table..."
|
|
python3 -c "
|
|
from migrations.add_events_table import upgrade
|
|
from app import create_app
|
|
app = create_app()
|
|
with app.app_context():
|
|
try:
|
|
upgrade()
|
|
print('Events table created successfully')
|
|
except Exception as e:
|
|
print(f'Error creating events table: {e}')
|
|
"
|
|
|
|
# Create notifs table
|
|
echo "Creating notifs table..."
|
|
python3 -c "
|
|
from migrations.add_notifs_table import upgrade
|
|
from app import create_app
|
|
app = create_app()
|
|
with app.app_context():
|
|
try:
|
|
upgrade()
|
|
print('Notifs table created successfully')
|
|
except Exception as e:
|
|
print(f'Error creating notifs table: {e}')
|
|
"
|
|
|
|
# Create default site settings if they don't exist
|
|
echo "Creating default site settings..."
|
|
python3 -c "
|
|
from app import create_app
|
|
from models import SiteSettings, db
|
|
app = create_app()
|
|
with app.app_context():
|
|
try:
|
|
settings = SiteSettings.get_settings()
|
|
print('Default site settings created successfully')
|
|
except Exception as e:
|
|
print(f'Error creating site settings: {e}')
|
|
"
|
|
|
|
# Initialize admin user
|
|
echo "Initializing admin user..."
|
|
python3 -c "
|
|
from init_admin import init_admin
|
|
init_admin()
|
|
"
|
|
|
|
# Start the application
|
|
echo "Starting application..."
|
|
exec gunicorn --bind 0.0.0.0:5000 app:app |