Commit f2faedb5 authored by George Papathanail's avatar George Papathanail
Browse files

feat: add app_deployments table and FK it to app_instances

parent 28bf3f04
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ from sqlalchemy.dialects.postgresql import UUID as PG_UUID
from sqlalchemy.ext.asyncio import AsyncAttrs
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

from open_exposure_gateway.domain.models.deployments.enums import AppDeploymentState
from open_exposure_gateway.domain.models.instances.enums import AppInstanceState
from open_exposure_gateway.domain.models.operations.enums import (
    OperationStatus,
@@ -165,6 +166,27 @@ class CallbackDeliveryRow(Base):
    state: Mapped[str] = mapped_column(String(32), nullable=False)


class AppDeploymentRow(AuditedMixin, Base):
    __tablename__ = "app_deployments"
    __table_args__ = (
        Index("idx_app_deployments_operation", "operation_id"),
        Index("idx_app_deployments_registration", "app_registration_id"),
    )

    app_deployment_id: Mapped[UUID] = mapped_column(PG_UUID(as_uuid=True), primary_key=True)
    operation_id: Mapped[UUID] = mapped_column(
        ForeignKey("operations.operation_id"), nullable=False
    )
    app_registration_id: Mapped[UUID] = mapped_column(
        ForeignKey("app_registrations.app_registration_id"), nullable=False
    )
    app_deployment_name: Mapped[str] = mapped_column(String(64), nullable=False)
    edge_cloud_zones: Mapped[list[str]] = mapped_column(JSONB, nullable=False)
    state: Mapped[AppDeploymentState] = mapped_column(
        _enum_type(AppDeploymentState), nullable=False
    )


class AppInstanceRow(AuditedMixin, Base):
    __tablename__ = "app_instances"
    __table_args__ = (
@@ -177,9 +199,9 @@ class AppInstanceRow(AuditedMixin, Base):
    operation_id: Mapped[UUID] = mapped_column(
        ForeignKey("operations.operation_id"), nullable=False
    )
    # No FK yet: app_deployments (multi-zone POST /deployments) is out of
    # scope for this MR.
    app_deployment_id: Mapped[UUID | None] = mapped_column(PG_UUID(as_uuid=True))
    app_deployment_id: Mapped[UUID | None] = mapped_column(
        ForeignKey("app_deployments.app_deployment_id")
    )
    app_registration_id: Mapped[UUID] = mapped_column(
        ForeignKey("app_registrations.app_registration_id"), nullable=False
    )