- database.py: PostgreSQL 연결 설정 및 세션 관리 - models.py: Project, File, Material SQLAlchemy 모델 정의 - schemas.py: Pydantic 요청/응답 스키마 정의 - 완전한 데이터베이스 연동 구조 완성
75 lines
2.8 KiB
Python
75 lines
2.8 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text, Numeric, ForeignKey
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
|
|
Base = declarative_base()
|
|
|
|
class Project(Base):
|
|
__tablename__ = "projects"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
official_project_code = Column(String(50), unique=True, index=True)
|
|
project_name = Column(String(200), nullable=False)
|
|
client_name = Column(String(100))
|
|
design_project_code = Column(String(50))
|
|
design_project_name = Column(String(200))
|
|
is_code_matched = Column(Boolean, default=False)
|
|
matched_by = Column(String(100))
|
|
matched_at = Column(DateTime)
|
|
status = Column(String(20), default='active')
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow)
|
|
description = Column(Text)
|
|
notes = Column(Text)
|
|
|
|
# 관계 설정
|
|
files = relationship("File", back_populates="project")
|
|
|
|
class File(Base):
|
|
__tablename__ = "files"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
project_id = Column(Integer, ForeignKey("projects.id"))
|
|
filename = Column(String(255), nullable=False)
|
|
original_filename = Column(String(255), nullable=False)
|
|
file_path = Column(String(500), nullable=False)
|
|
revision = Column(String(20), default='Rev.0')
|
|
upload_date = Column(DateTime, default=datetime.utcnow)
|
|
uploaded_by = Column(String(100))
|
|
file_type = Column(String(10))
|
|
file_size = Column(Integer)
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
# 관계 설정
|
|
project = relationship("Project", back_populates="files")
|
|
materials = relationship("Material", back_populates="file")
|
|
|
|
class Material(Base):
|
|
__tablename__ = "materials"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
file_id = Column(Integer, ForeignKey("files.id"))
|
|
line_number = Column(Integer)
|
|
original_description = Column(Text, nullable=False)
|
|
classified_category = Column(String(50))
|
|
classified_subcategory = Column(String(100))
|
|
material_grade = Column(String(50))
|
|
schedule = Column(String(20))
|
|
size_spec = Column(String(50))
|
|
quantity = Column(Numeric(10, 3), nullable=False)
|
|
unit = Column(String(10), nullable=False)
|
|
drawing_name = Column(String(100))
|
|
area_code = Column(String(20))
|
|
line_no = Column(String(50))
|
|
classification_confidence = Column(Numeric(3, 2))
|
|
is_verified = Column(Boolean, default=False)
|
|
verified_by = Column(String(100))
|
|
verified_at = Column(DateTime)
|
|
drawing_reference = Column(String(100))
|
|
notes = Column(Text)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# 관계 설정
|
|
file = relationship("File", back_populates="materials")
|