1. sqlalchemy CRUD 예제 실습
2. callcenter 프로젝트 제작중
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# 강제로 회원가입
|
||||
from sqlalchemy.orm import Session
|
||||
from backend.repository.db_init import SessionLocal
|
||||
from backend.repository.models import Customer
|
||||
|
||||
db = SessionLocal()
|
||||
|
||||
DEFAULT_CUSTOMERS = [
|
||||
Customer(name="홍길동", phone="010-1234-5678"),
|
||||
Customer(name="최철수", phone="010-4321-8765"),
|
||||
Customer(name="박영희", phone="010-5678-1234"),
|
||||
]
|
||||
|
||||
def seed_customers(db: Session):
|
||||
"""
|
||||
customer 테이블에 기본(연습용) 회원 데이터 삽입
|
||||
(중복 실행 방지 : 이미 데이터가 있으면 건너뜀)
|
||||
"""
|
||||
|
||||
existing = db.query(Customer).first()
|
||||
if existing:
|
||||
print("[Seed] customer 테이블에 이미 데이터가 있습니다.")
|
||||
return
|
||||
|
||||
db.add_all(DEFAULT_CUSTOMERS)
|
||||
db.commit()
|
||||
db.close()
|
||||
print(f"[Seed] 기본 회원 {len(DEFAULT_CUSTOMERS)}명 생성 완료")
|
||||
Reference in New Issue
Block a user