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