fixed app unhealthy status
This commit is contained in:
22
app.py
22
app.py
@@ -4,17 +4,35 @@ from flask_bootstrap import Bootstrap5
|
|||||||
from models import db, Feature
|
from models import db, Feature
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# Database config
|
||||||
db_user = os.getenv('DB_USER')
|
db_user = os.getenv('DB_USER')
|
||||||
db_pass = os.getenv('DB_PASS')
|
db_pass = os.getenv('DB_PASS')
|
||||||
db_name = os.getenv('DB_NAME')
|
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
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
bootstrap = Bootstrap5(app)
|
bootstrap = Bootstrap5(app)
|
||||||
db.init_app(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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
with app.app_context():
|
|
||||||
features = Feature.query.all()
|
features = Feature.query.all()
|
||||||
return render_template('index.html', features=features)
|
return render_template('index.html', features=features)
|
||||||
|
|
||||||
|
|
||||||
|
# Optional: nice health endpoint that doesn't touch DB
|
||||||
|
@app.route('/health')
|
||||||
|
def health():
|
||||||
|
return "OK", 200
|
||||||
|
|||||||
Reference in New Issue
Block a user