""" 제품 태깅 시스템 스키마 적용 """ 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()