Files
devops/app.py
gitea 9fc2316459
All checks were successful
Build and Deploy Demo App / build (push) Successful in 15s
Build and Deploy Demo App / test (push) Successful in 11s
Build and Deploy Demo App / scan (push) Successful in 20s
Build and Deploy Demo App / deploy (push) Successful in 1m10s
fixed app unhealthy status
2025-11-26 14:38:58 +03:30

39 lines
1.1 KiB
Python

import os
from flask import Flask, render_template
from flask_bootstrap import Bootstrap5
from models import db, Feature
app = Flask(__name__)
# Database config
db_user = os.getenv('DB_USER')
db_pass = os.getenv('DB_PASS')
db_name = os.getenv('DB_NAME')
app.config['SQLALCHEMY_DATABASE_URI'] = (
f'postgresql://{db_user}:{db_pass}@db:5432/{db_name}'
if db_user else 'sqlite:///:memory:'
)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
bootstrap = Bootstrap5(app)
db.init_app(app)
# ────────────────────────────────
# THIS IS THE MISSING PART:
# Create tables + seed data ONCE at startup
# ────────────────────────────────
with app.app_context():
db.create_all() # ← Creates the "feature" table if missing
Feature.seed_db() # ← Now works without error
@app.route('/')
def index():
features = Feature.query.all()
return render_template('index.html', features=features)
# Optional: nice health endpoint that doesn't touch DB
@app.route('/health')
def health():
return "OK", 200