| 730 | |
| 731 | |
| 732 | class Deployment(Base): |
| 733 | __tablename__: str = "deployment" |
| 734 | |
| 735 | id: Mapped[str] = mapped_column( |
| 736 | String(32), primary_key=True, default=lambda: token_hex(16) |
| 737 | ) |
| 738 | project_id: Mapped[str] = mapped_column(ForeignKey("project.id"), index=True) |
| 739 | repo_id: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True) |
| 740 | repo_full_name: Mapped[str] = mapped_column(String(255), nullable=False, index=True) |
| 741 | environment_id: Mapped[str] = mapped_column(String(8), nullable=False) |
| 742 | branch: Mapped[str] = mapped_column(String(255), index=True) |
| 743 | commit_sha: Mapped[str] = mapped_column(String(40), index=True) |
| 744 | commit_meta: Mapped[dict[str, object]] = mapped_column( |
| 745 | JSON, nullable=False, default=dict |
| 746 | ) |
| 747 | config: Mapped[dict[str, object]] = mapped_column( |
| 748 | JSON, nullable=False, default=dict |
| 749 | ) |
| 750 | image: Mapped[str | None] = mapped_column(String(512), nullable=True) |
| 751 | _env_vars: Mapped[str] = mapped_column("env_vars", Text, nullable=False, default="") |
| 752 | job_id: Mapped[str | None] = mapped_column(String(36), nullable=True) |
| 753 | error: Mapped[dict[str, object] | None] = mapped_column(JSON, nullable=True) |
| 754 | container_id: Mapped[str | None] = mapped_column(String(64), nullable=True) |
| 755 | container_status: Mapped[str | None] = mapped_column( |
| 756 | SQLAEnum("running", "stopped", "removed", name="deployment_container_status"), |
| 757 | nullable=True, |
| 758 | ) |
| 759 | status: Mapped[str] = mapped_column( |
| 760 | SQLAEnum( |
| 761 | "prepare", |
| 762 | "deploy", |
| 763 | "finalize", |
| 764 | "fail", |
| 765 | "completed", |
| 766 | name="deployment_status", |
| 767 | ), |
| 768 | nullable=False, |
| 769 | default="prepare", |
| 770 | ) |
| 771 | conclusion: Mapped[str] = mapped_column( |
| 772 | SQLAEnum( |
| 773 | "succeeded", "failed", "canceled", "skipped", name="deployment_conclusion" |
| 774 | ), |
| 775 | nullable=True, |
| 776 | ) |
| 777 | trigger: Mapped[str] = mapped_column( |
| 778 | SQLAEnum("webhook", "user", "api", name="deployment_trigger"), |
| 779 | nullable=False, |
| 780 | default="user", |
| 781 | ) |
| 782 | created_by_user_id: Mapped[int | None] = mapped_column( |
| 783 | ForeignKey("user.id", use_alter=True, ondelete="SET NULL"), nullable=True |
| 784 | ) |
| 785 | created_at: Mapped[datetime] = mapped_column( |
| 786 | index=True, nullable=False, default=utc_now |
| 787 | ) |
| 788 | concluded_at: Mapped[datetime | None] = mapped_column(index=True, nullable=True) |
| 789 | |