bug fixes

This commit is contained in:
2026-02-14 20:06:39 -06:00
parent 04ea648950
commit 3ccd11153c
7 changed files with 131 additions and 39 deletions

View File

@@ -155,8 +155,48 @@ def health_check():
return flask.jsonify({"status": "ok"}), 200
def _seed_templates_if_empty():
"""Auto-seed routine templates if the table is empty."""
try:
count = postgres.count("routine_templates")
if count == 0:
import logging
logging.getLogger(__name__).info("No templates found, seeding from seed_templates.sql...")
seed_path = os.path.join(os.path.dirname(__file__), "..", "config", "seed_templates.sql")
if os.path.exists(seed_path):
with open(seed_path, "r") as f:
sql = f.read()
with postgres.get_cursor() as cur:
cur.execute(sql)
logging.getLogger(__name__).info("Templates seeded successfully.")
except Exception as e:
import logging
logging.getLogger(__name__).warning(f"Failed to seed templates: {e}")
def _seed_rewards_if_empty():
"""Auto-seed reward pool if the table is empty."""
try:
count = postgres.count("reward_pool")
if count == 0:
import logging
logging.getLogger(__name__).info("No rewards found, seeding from seed_rewards.sql...")
seed_path = os.path.join(os.path.dirname(__file__), "..", "config", "seed_rewards.sql")
if os.path.exists(seed_path):
with open(seed_path, "r") as f:
sql = f.read()
with postgres.get_cursor() as cur:
cur.execute(sql)
logging.getLogger(__name__).info("Rewards seeded successfully.")
except Exception as e:
import logging
logging.getLogger(__name__).warning(f"Failed to seed rewards: {e}")
if __name__ == "__main__":
for module in ROUTE_MODULES:
if hasattr(module, "register"):
module.register(app)
_seed_templates_if_empty()
_seed_rewards_if_empty()
app.run(host="0.0.0.0", port=5000)