- product_master 테이블: 제품 마스터 (바코드, 이름, 성분, 태그) - product_categories: 제품 카테고리 22개 (진통제, 소화제 등) - product_category_mapping: 다대다 매핑 (하나의 제품이 여러 카테고리) - disease_codes: 질병 코드 ICD-10 12개 - disease_product_mapping: 질병-제품 매핑 - 샘플 제품 3개 추가 (탁센, 베아제, 마그비맥스) - BARCODE 컬럼 95.79% 보유율 확인 - 온톨로지 기반 추천 시스템 설계 문서 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
"""
|
|
제품 태깅 시스템 스키마 적용
|
|
"""
|
|
|
|
import sqlite3
|
|
import os
|
|
|
|
def apply_product_schema():
|
|
"""product_tagging_schema.sql을 mileage.db에 적용"""
|
|
db_path = os.path.join(os.path.dirname(__file__), 'db', 'mileage.db')
|
|
schema_path = os.path.join(os.path.dirname(__file__), 'db', 'product_tagging_schema.sql')
|
|
|
|
print(f"DB 경로: {db_path}")
|
|
print(f"스키마 경로: {schema_path}")
|
|
|
|
# 스키마 파일 읽기
|
|
with open(schema_path, 'r', encoding='utf-8') as f:
|
|
schema_sql = f.read()
|
|
|
|
# DB 연결 및 실행
|
|
conn = sqlite3.connect(db_path)
|
|
cursor = conn.cursor()
|
|
|
|
try:
|
|
# 전체 스키마 실행
|
|
cursor.executescript(schema_sql)
|
|
conn.commit()
|
|
|
|
print("\n[OK] 제품 태깅 시스템 스키마 적용 완료!")
|
|
|
|
# 테이블 확인
|
|
cursor.execute("""
|
|
SELECT name FROM sqlite_master
|
|
WHERE type='table' AND name LIKE '%product%' OR name LIKE '%disease%'
|
|
ORDER BY name
|
|
""")
|
|
|
|
tables = cursor.fetchall()
|
|
print("\n생성된 테이블:")
|
|
for table in tables:
|
|
print(f" - {table[0]}")
|
|
|
|
# 초기 데이터 확인
|
|
cursor.execute("SELECT COUNT(*) FROM product_categories")
|
|
cat_count = cursor.fetchone()[0]
|
|
print(f"\n제품 카테고리: {cat_count}개")
|
|
|
|
cursor.execute("SELECT COUNT(*) FROM disease_codes")
|
|
disease_count = cursor.fetchone()[0]
|
|
print(f"질병 코드: {disease_count}개")
|
|
|
|
cursor.execute("SELECT COUNT(*) FROM disease_product_mapping")
|
|
mapping_count = cursor.fetchone()[0]
|
|
print(f"질병-제품 매핑: {mapping_count}개")
|
|
|
|
# 카테고리 목록 출력
|
|
print("\n제품 카테고리 목록:")
|
|
cursor.execute("SELECT category_name, description FROM product_categories ORDER BY category_id")
|
|
categories = cursor.fetchall()
|
|
for cat, desc in categories:
|
|
print(f" - {cat:15} : {desc}")
|
|
|
|
except Exception as e:
|
|
print(f"\n[ERROR] 오류 발생: {e}")
|
|
conn.rollback()
|
|
finally:
|
|
conn.close()
|
|
|
|
if __name__ == '__main__':
|
|
apply_product_schema()
|