From c97f73ab0c60044ebe288d54eabb31c1d5c7475e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A8=B8=EB=8B=88=ED=8E=98=EB=8B=88?= Date: Wed, 13 May 2026 22:48:01 +0900 Subject: [PATCH] fix: delete all duplicate portfolios in seed_data to ensure idempotency --- backend/scripts/seed_data.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/scripts/seed_data.py b/backend/scripts/seed_data.py index b200891..dc3c55a 100644 --- a/backend/scripts/seed_data.py +++ b/backend/scripts/seed_data.py @@ -121,15 +121,16 @@ def seed(db: Session): print("ERROR: No user found in database. Create a user first.") return - # Delete existing portfolio if present (cascade deletes related records) - existing = db.query(Portfolio).filter( + # Delete all existing portfolios with this name (cascade deletes related records) + existing_list = db.query(Portfolio).filter( Portfolio.user_id == user.id, Portfolio.name == "연금 포트폴리오", - ).first() - if existing: + ).all() + for existing in existing_list: db.delete(existing) - db.flush() print(f"Deleted existing portfolio (id={existing.id})") + if existing_list: + db.flush() # Create portfolio portfolio = Portfolio(