from __future__ import annotations from datetime import date, datetime from sqlalchemy import CheckConstraint, Date, DateTime, ForeignKey, Index, Integer, Numeric, String, func, text from sqlalchemy.orm import Mapped, mapped_column, relationship from src.db.base import Base class Project(Base): __tablename__ = "project" __table_args__ = ( CheckConstraint("level IN ('program', 'project')", name="project_level_check"), CheckConstraint( "placement_type IS NULL OR placement_type IN ('own', 'rent', 'other')", name="project_placement_type_check", ), CheckConstraint( "project_type IS NULL OR project_type IN ('current', 'development')", name="project_project_type_check", ), CheckConstraint( "vsp_format IS NULL OR vsp_format IN ('office', 'standalone', 'atm', 'other')", name="project_vsp_format_check", ), CheckConstraint( text("name IS NOT NULL AND name <> ''"), name="chk_v3_project_name", ), CheckConstraint( "status IS NULL OR status IN ('created', 'agreed', 'archived')", name="project_status_check", ), CheckConstraint( "funding_by_ko_decision IS NULL OR funding_by_ko_decision IN ('prrs_budget', 'bank_reserve')", name="project_funding_ko_check", ), Index("ix_v3_project_ssp", "org_unit_id"), {"schema": "v3"}, ) id: Mapped[int] = mapped_column(primary_key=True) name: Mapped[str | None] = mapped_column(String) level: Mapped[str | None] = mapped_column(String) parent_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("v3.project.id")) project_type: Mapped[str | None] = mapped_column(String) vsp_format: Mapped[str | None] = mapped_column(String) placement_type: Mapped[str | None] = mapped_column(String) object_address: Mapped[str | None] = mapped_column(String) staff_count: Mapped[int | None] = mapped_column(Integer) total_area: Mapped[float | None] = mapped_column(Numeric) org_unit_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("v3.org_unit.id")) created_at: Mapped[datetime | None] = mapped_column(DateTime, server_default=func.now()) status: Mapped[str | None] = mapped_column(String, server_default=text("'created'")) technical_number: Mapped[str | None] = mapped_column(String) krf_decision_date: Mapped[date | None] = mapped_column(Date) fk_decision_date: Mapped[date | None] = mapped_column(Date) board_decision_date: Mapped[date | None] = mapped_column(Date) open_relocate_close_date: Mapped[date | None] = mapped_column(Date) funding_by_ko_decision: Mapped[str | None] = mapped_column(String) # parent = relationship("Project", remote_side="Project.id", back_populates="children") # children: Mapped[list["Project"]] = relationship("Project", back_populates="parent") # type: ignore # org_unit = relationship("OrgUnit", back_populates="projects") # budget_lines: Mapped[list["BudgetLine"]] = relationship("BudgetLine", back_populates="project") # type: ignore rf_project_reports: Mapped[list["RfProjectReport"]] = relationship("RfProjectReport", back_populates="project") # type: ignore