from flask import Flask, jsonify from sqlalchemy import inspect, text from config import Config from models import db from routes import register_routes from flask_cors import CORS app = Flask(__name__) CORS(app, resources={r"/api/*": {"origins": "*"}},allow_headers="*") app.config.from_object(Config) db.init_app(app) def ensure_schema(): """Idempotently add columns that aren't created by db.create_all() because the table already exists. Add new entries here when introducing new columns.""" inspector = inspect(db.engine) if 'bre_policies' in inspector.get_table_names(): cols = {c['name'] for c in inspector.get_columns('bre_policies')} if 'is_live' not in cols: with db.engine.begin() as conn: conn.execute(text( "ALTER TABLE bre_policies ADD COLUMN is_live BOOLEAN DEFAULT FALSE" )) with app.app_context(): db.create_all() ensure_schema() @app.route('/') def index(): return jsonify({"message": "Policy Rule API"}), 200 register_routes(app) if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=3000)