fixed app unhealthy status
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

This commit is contained in:
2025-11-26 14:38:58 +03:30
parent 0c5eaa19cd
commit 9fc2316459

24
app.py
View File

@@ -4,17 +4,35 @@ 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:' # Fallback only if no env (for tests)
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():
with app.app_context():
features = Feature.query.all()
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