""" RAG Minutes 테이블 초기화 스크립트 """ import psycopg2 import sys from pathlib import Path # 프로젝트 루트를 Python 경로에 추가 sys.path.insert(0, str(Path(__file__).parent.parent)) from src.utils.config import load_config, get_database_url def init_rag_minutes_table(db_url: str, migration_file: str): """ RAG Minutes 테이블 초기화 Args: db_url: 데이터베이스 연결 URL migration_file: 마이그레이션 SQL 파일 경로 """ try: print(f"데이터베이스 연결 중...") conn = psycopg2.connect(db_url) cur = conn.cursor() print(f"마이그레이션 파일 읽기: {migration_file}") with open(migration_file, 'r', encoding='utf-8') as f: sql = f.read() print("마이그레이션 실행 중...") cur.execute(sql) conn.commit() print("✓ RAG Minutes 테이블 초기화 완료") # 테이블 확인 cur.execute(""" SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'rag_minutes' """) count = cur.fetchone()[0] if count > 0: print(f"✓ rag_minutes 테이블이 생성되었습니다") # 인덱스 확인 cur.execute(""" SELECT indexname FROM pg_indexes WHERE tablename = 'rag_minutes' """) indexes = cur.fetchall() print(f"✓ 생성된 인덱스: {len(indexes)}개") for idx in indexes: print(f" - {idx[0]}") else: print("✗ 테이블 생성 실패") cur.close() conn.close() except Exception as e: print(f"✗ 에러 발생: {str(e)}") raise if __name__ == "__main__": # 설정 로드 config_path = Path(__file__).parent.parent / "config.yaml" config = load_config(str(config_path)) db_url = get_database_url(config) db_url = "postgresql://hgzerouser:Hi5Jessica!@4.217.133.186:5432/ragdb" # 마이그레이션 파일 경로 migration_file = Path(__file__).parent.parent / "migrations" / "V1__create_rag_minutes_table.sql" if not migration_file.exists(): print(f"✗ 마이그레이션 파일을 찾을 수 없습니다: {migration_file}") sys.exit(1) # 초기화 실행 init_rag_minutes_table(db_url, str(migration_file))