testing entrypoint
This commit is contained in:
14
app.py
14
app.py
@@ -76,9 +76,21 @@ def create_app():
|
||||
@app.route('/health')
|
||||
def health_check():
|
||||
try:
|
||||
# Check database connection
|
||||
# Check database connection with a timeout
|
||||
db.session.execute(text('SELECT 1'))
|
||||
db.session.commit()
|
||||
|
||||
# Check if we can actually query a table
|
||||
try:
|
||||
User.query.first()
|
||||
except Exception as e:
|
||||
app.logger.error(f"Database query failed: {str(e)}")
|
||||
return jsonify({
|
||||
'status': 'unhealthy',
|
||||
'error': f"Database query failed: {str(e)}",
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}), 500
|
||||
|
||||
return jsonify({
|
||||
'status': 'healthy',
|
||||
'database': 'connected',
|
||||
|
||||
@@ -38,66 +38,55 @@ until PGPASSWORD=$POSTGRES_PASSWORD psql -h db -U $POSTGRES_USER -d $POSTGRES_DB
|
||||
done
|
||||
echo "PostgreSQL is up - executing command"
|
||||
|
||||
# Run migrations
|
||||
echo "Running database migrations..."
|
||||
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..."
|
||||
# Run all initialization in a single Python script to avoid multiple Flask instances
|
||||
echo "Running initialization..."
|
||||
python3 -c "
|
||||
from app import create_app
|
||||
from models import SiteSettings, db
|
||||
from migrations.add_events_table import upgrade as upgrade_events
|
||||
from migrations.add_notifs_table import upgrade as upgrade_notifs
|
||||
from init_admin import init_admin
|
||||
from utils.email_templates import create_default_templates
|
||||
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
# Run migrations
|
||||
print('Running database migrations...')
|
||||
from flask_migrate import upgrade
|
||||
upgrade()
|
||||
|
||||
# Create events table
|
||||
print('Creating events table...')
|
||||
try:
|
||||
upgrade_events()
|
||||
print('Events table created successfully')
|
||||
except Exception as e:
|
||||
print(f'Error creating events table: {e}')
|
||||
|
||||
# Create notifs table
|
||||
print('Creating notifs table...')
|
||||
try:
|
||||
upgrade_notifs()
|
||||
print('Notifs table created successfully')
|
||||
except Exception as e:
|
||||
print(f'Error creating notifs table: {e}')
|
||||
|
||||
# Create default site settings
|
||||
print('Creating default site settings...')
|
||||
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
|
||||
print('Initializing admin user...')
|
||||
init_admin()
|
||||
"
|
||||
|
||||
# Create admin user
|
||||
echo "Creating admin user..."
|
||||
flask create-admin
|
||||
|
||||
# Create default templates
|
||||
echo "Creating default templates..."
|
||||
flask create-default-templates
|
||||
print('Creating default templates...')
|
||||
create_default_templates()
|
||||
"
|
||||
|
||||
# Start the application
|
||||
echo "Starting application..."
|
||||
|
||||
Reference in New Issue
Block a user