From 76638016c1b19e77c9271433117e4f4464f47538 Mon Sep 17 00:00:00 2001 From: Peter Woolery Date: Sat, 9 May 2026 12:47:25 -0700 Subject: [PATCH] feat: one-time family profile seed script --- scripts/seed_family.py | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 scripts/seed_family.py diff --git a/scripts/seed_family.py b/scripts/seed_family.py new file mode 100644 index 0000000..f7249ce --- /dev/null +++ b/scripts/seed_family.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +""" +One-time seed: creates the family profile + members. + +Edit the MEMBERS list below to set real names and emails, then run: + + docker cp scripts/seed_family.py mealplanner-backend-1:/app/seed_family.py + docker compose --env-file .env.test exec backend python /app/seed_family.py + +Safe to re-run — exits early if a profile already exists. +""" +import os +import sys + +# ── Edit before running ─────────────────────────────────────────────────────── +FAMILY_NAME = "Woolery" +FAMILY_CALORIE_TARGET = 500 # per serving per meal +HOUSEHOLD_SIZE = 4 +ADULT_COUNT = 2 +CHILD_COUNT = 2 + +MEMBERS = [ + {"name": "Peter", "email": "peter@research.bike", "role": "adult", "likes_mushrooms": True}, + {"name": "Wife", "email": "wife@example.com", "role": "adult", "likes_mushrooms": False}, + {"name": "Kid 1", "email": "", "role": "child", "likes_mushrooms": False}, + {"name": "Kid 2", "email": "", "role": "child", "likes_mushrooms": False}, +] +# ───────────────────────────────────────────────────────────────────────────── + +sys.path.insert(0, "/app") + +from app.database import SessionLocal +from app.models import FamilyProfile, FamilyMember, FamilyMemberRole + +db = SessionLocal() +try: + existing = db.query(FamilyProfile).first() + if existing: + print(f"Family profile already exists (id={existing.id}). Nothing to do.") + sys.exit(0) + + profile = FamilyProfile( + name=FAMILY_NAME, + household_size=HOUSEHOLD_SIZE, + adult_count=ADULT_COUNT, + child_count=CHILD_COUNT, + calorie_target=FAMILY_CALORIE_TARGET, + ) + db.add(profile) + db.flush() + print(f"Created family profile '{FAMILY_NAME}' id={profile.id}") + + for m in MEMBERS: + if not m["email"]: + print(f" Skipping {m['name']} — no email set (edit MEMBERS to add one)") + continue + member = FamilyMember( + family_profile_id=profile.id, + name=m["name"], + email=m["email"], + role=FamilyMemberRole[m["role"].upper()], + likes_mushrooms=m["likes_mushrooms"], + ) + db.add(member) + print(f" Added: {m['name']} <{m['email']}> role={m['role']}") + + db.commit() + print("Done.") +finally: + db.close()