first commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
from flask import Flask
|
||||
from extensions import db, login_manager, csrf, hash_password, check_password
|
||||
from sqlalchemy import text
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'team-tryouts-secret-key-change-in-production')
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///team_tryouts.db'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
app.config['WTF_CSRF_ENABLED'] = True
|
||||
|
||||
db.init_app(app)
|
||||
login_manager.init_app(app)
|
||||
csrf.init_app(app)
|
||||
|
||||
from routes.auth import auth_bp
|
||||
from routes.tryouts import tryouts_bp
|
||||
from routes.evaluations import evaluations_bp
|
||||
from routes.users import users_bp
|
||||
from routes.main import main_bp
|
||||
from routes.teams import teams_bp
|
||||
|
||||
app.register_blueprint(auth_bp)
|
||||
app.register_blueprint(tryouts_bp)
|
||||
app.register_blueprint(evaluations_bp)
|
||||
app.register_blueprint(users_bp)
|
||||
app.register_blueprint(main_bp)
|
||||
app.register_blueprint(teams_bp)
|
||||
|
||||
with app.app_context():
|
||||
import models
|
||||
from models import User
|
||||
try:
|
||||
# Check if the database schema is up to date by testing a query
|
||||
# that uses all model columns
|
||||
db.session.execute(text('SELECT games FROM users LIMIT 1'))
|
||||
db.create_all()
|
||||
except Exception:
|
||||
# If there's a schema mismatch, drop and recreate all tables
|
||||
db.session.rollback()
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
|
||||
# Seed database if empty
|
||||
if User.query.count() == 0:
|
||||
from seed import seed_database
|
||||
seed_database()
|
||||
|
||||
return app
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = create_app()
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
Reference in New Issue
Block a user