fix: delete all duplicate portfolios in seed_data to ensure idempotency
All checks were successful
Deploy to Production / deploy (push) Successful in 2m2s
All checks were successful
Deploy to Production / deploy (push) Successful in 2m2s
This commit is contained in:
parent
fc0a24888d
commit
c97f73ab0c
@ -121,15 +121,16 @@ def seed(db: Session):
|
|||||||
print("ERROR: No user found in database. Create a user first.")
|
print("ERROR: No user found in database. Create a user first.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Delete existing portfolio if present (cascade deletes related records)
|
# Delete all existing portfolios with this name (cascade deletes related records)
|
||||||
existing = db.query(Portfolio).filter(
|
existing_list = db.query(Portfolio).filter(
|
||||||
Portfolio.user_id == user.id,
|
Portfolio.user_id == user.id,
|
||||||
Portfolio.name == "연금 포트폴리오",
|
Portfolio.name == "연금 포트폴리오",
|
||||||
).first()
|
).all()
|
||||||
if existing:
|
for existing in existing_list:
|
||||||
db.delete(existing)
|
db.delete(existing)
|
||||||
db.flush()
|
|
||||||
print(f"Deleted existing portfolio (id={existing.id})")
|
print(f"Deleted existing portfolio (id={existing.id})")
|
||||||
|
if existing_list:
|
||||||
|
db.flush()
|
||||||
|
|
||||||
# Create portfolio
|
# Create portfolio
|
||||||
portfolio = Portfolio(
|
portfolio = Portfolio(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user