- PostgreSQL jobs 테이블 스키마 생성 - 더미 프로젝트 데이터 2개 추가 (J24-001, J24-002) - 엔지니어링 업계 구조 반영 (엔드유저-클라이언트-EPC) - 가상환경 경로 이슈 해결 방법 문서화
74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
전체 데이터베이스 설정 및 더미 데이터 생성
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from sqlalchemy import create_engine, text
|
|
|
|
# 프로젝트 루트를 Python path에 추가
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
def setup_database():
|
|
"""데이터베이스 전체 설정"""
|
|
|
|
try:
|
|
from app.database import engine
|
|
print("✅ 기존 데이터베이스 연결 사용")
|
|
except ImportError:
|
|
# 개발용 직접 연결
|
|
DATABASE_URL = "sqlite:///./test.db"
|
|
engine = create_engine(DATABASE_URL)
|
|
print("⚠️ 개발용 SQLite 연결")
|
|
|
|
try:
|
|
with engine.connect() as conn:
|
|
print("🏗️ 1단계: jobs 테이블 생성...")
|
|
|
|
# jobs 테이블 생성 SQL 실행
|
|
with open('scripts/01_create_jobs_table.sql', 'r', encoding='utf-8') as f:
|
|
sql_commands = f.read().split(';')
|
|
for command in sql_commands:
|
|
command = command.strip()
|
|
if command:
|
|
conn.execute(text(command))
|
|
|
|
print("✅ jobs 테이블 생성 완료")
|
|
|
|
print("🔧 2단계: files 테이블 수정...")
|
|
|
|
# files 테이블 수정 (선택적)
|
|
try:
|
|
with open('scripts/02_modify_files_table.sql', 'r', encoding='utf-8') as f:
|
|
sql_commands = f.read().split(';')
|
|
for command in sql_commands:
|
|
command = command.strip()
|
|
if command and not command.startswith('--'):
|
|
conn.execute(text(command))
|
|
print("✅ files 테이블 수정 완료")
|
|
except Exception as e:
|
|
print(f"⚠️ files 테이블 수정 건너뜀: {e}")
|
|
|
|
# 커밋
|
|
conn.commit()
|
|
|
|
print("🎯 3단계: 더미 데이터 생성...")
|
|
# 더미 데이터 스크립트 실행
|
|
exec(open('scripts/03_insert_dummy_data.py').read())
|
|
|
|
print("\n🎉 전체 설정 완료!")
|
|
print("\n📋 다음 단계:")
|
|
print(" 1. API 서버 실행")
|
|
print(" 2. GET /jobs 엔드포인트 테스트")
|
|
print(" 3. Job 선택 후 BOM 파일 업로드")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 데이터베이스 설정 실패: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
setup_database()
|