diff --git a/api/app.py b/api/app.py index 955cc18..da31695 100644 --- a/api/app.py +++ b/api/app.py @@ -39,22 +39,24 @@ def create_app(): db.create_all() if os.getenv("BOT_USER") is not None and os.getenv("BOT_PASSWORD") is not None: - bot = User( - username=os.getenv("BOT_USER"), - password=hash_password(os.getenv("BOT_PASSWORD")), - admin=False - ) - db.session.add(bot) - db.session.commit() + if db.session.query(User).filter_by(username=os.getenv("BOT_USER")).first() is None: # Check if user already exist + bot = User( + username=os.getenv("BOT_USER"), + password=hash_password(os.getenv("BOT_PASSWORD")), + admin=False + ) + db.session.add(bot) + db.session.commit() if os.getenv("ADMIN_USER") is not None and os.getenv("ADMIN_PASSWORD") is not None: - admin = User( - username=os.getenv("ADMIN_USER"), - password=hash_password(os.getenv("ADMIN_PASSWORD")), - admin=True - ) - db.session.add(admin) - db.session.commit() + if db.session.query(User).filter_by(username=os.getenv("ADMIN_USER")).first() is None: # Check if user already exist + admin = User( + username=os.getenv("ADMIN_USER"), + password=hash_password(os.getenv("ADMIN_PASSWORD")), + admin=True + ) + db.session.add(admin) + db.session.commit() return application