from app import create_app, db
from app.models import User
import pymysql

app = create_app()

@app.before_first_request
def check_db_connection():
    try:
        # 使用SQLAlchemy检查连接
        db.session.execute("SELECT 1")
        app.logger.info("数据库连接成功")
    except Exception as e:
        app.logger.error(f"数据库连接错误: {str(e)}")

@app.shell_context_processor
def make_shell_context():
    return {'db': db, 'User': User}

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=40911, debug=True)