From f58413784d5cec665fbd86221fffca76c0e4007c Mon Sep 17 00:00:00 2001 From: Abram Date: Tue, 3 Dec 2024 12:43:18 +0100 Subject: [PATCH 1/3] feat (backend): add Universional, Versioned, Header & Tags DBA abstract models --- .../dbs/postgres/shared/dbas.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py b/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py index 86d2c15e7f..7053951b87 100644 --- a/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py +++ b/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py @@ -1,4 +1,5 @@ -from sqlalchemy import Column, UUID, TIMESTAMP, func +from sqlalchemy.dialects.postgresql import JSONB +from sqlalchemy import Column, String, UUID, TIMESTAMP, func, Integer class ProjectScopeDBA: @@ -27,3 +28,30 @@ class LifecycleDBA: UUID(as_uuid=True), nullable=True, ) + + +class UniversionalDBA: + __abstract__ = True + + slug = Column(String, nullable=False) + + +class HeaderDBA: + __abstract__ = True + + name = Column(String, nullable=True) + description = Column(String, nullable=True) + + +class VersionedDBA(LifecycleDBA): + __abstract__ = True + + slug = Column(String, nullable=False) + version = Column(Integer, nullable=False) + id = Column(UUID(as_uuid=True), nullable=False) + + +class TagsDBA: + __abstract__ = True + + tags = Column(JSONB(none_as_null=True), nullable=True) From 9b317cf42ca070fab1ae4bc8c9cf0da69c997e87 Mon Sep 17 00:00:00 2001 From: Abram Date: Wed, 4 Dec 2024 09:36:50 +0100 Subject: [PATCH 2/3] refactor (backend): add project, universal and header dtos and added id to the UniversalDBA --- agenta-backend/agenta_backend/core/shared/dtos.py | 14 ++++++++++++++ .../agenta_backend/dbs/postgres/shared/dbas.py | 1 + 2 files changed, 15 insertions(+) diff --git a/agenta-backend/agenta_backend/core/shared/dtos.py b/agenta-backend/agenta_backend/core/shared/dtos.py index 85c3b303aa..1d38fb3ed3 100644 --- a/agenta-backend/agenta_backend/core/shared/dtos.py +++ b/agenta-backend/agenta_backend/core/shared/dtos.py @@ -10,3 +10,17 @@ class LifecycleDTO(BaseModel): updated_at: Optional[datetime] = None updated_by_id: Optional[UUID] = None + + +class ProjectDTO(BaseModel): + project_id: UUID + + +class UniversionalDTO(BaseModel): + id: UUID + slug: Optional[str] = None + + +class HeaderDTO(BaseModel): + name: Optional[str] = None + description: Optional[str] = None diff --git a/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py b/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py index 7053951b87..add9eddd7e 100644 --- a/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py +++ b/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py @@ -33,6 +33,7 @@ class LifecycleDBA: class UniversionalDBA: __abstract__ = True + id = Column(UUID(as_uuid=True), nullable=False, primary_key=True, default=uuid.uuid4) # type: ignore slug = Column(String, nullable=False) From d504e35295cb5579ec1d1a11e5c1a639cf48d7ff Mon Sep 17 00:00:00 2001 From: Abram Date: Wed, 4 Dec 2024 13:34:29 +0100 Subject: [PATCH 3/3] refactor (backend): break down unversioned dto into identifier and slug dtos --- agenta-backend/agenta_backend/core/shared/dtos.py | 11 +++++------ .../agenta_backend/dbs/postgres/shared/dbas.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/agenta-backend/agenta_backend/core/shared/dtos.py b/agenta-backend/agenta_backend/core/shared/dtos.py index 1d38fb3ed3..ac7efb69c7 100644 --- a/agenta-backend/agenta_backend/core/shared/dtos.py +++ b/agenta-backend/agenta_backend/core/shared/dtos.py @@ -6,19 +6,18 @@ class LifecycleDTO(BaseModel): - created_at: datetime + created_at: Optional[datetime] = None updated_at: Optional[datetime] = None updated_by_id: Optional[UUID] = None -class ProjectDTO(BaseModel): - project_id: UUID +class IdentifierDTO(BaseModel): + id: UUID -class UniversionalDTO(BaseModel): - id: UUID - slug: Optional[str] = None +class SlugDTO(BaseModel): + slug: str class HeaderDTO(BaseModel): diff --git a/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py b/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py index add9eddd7e..05b0eb0752 100644 --- a/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py +++ b/agenta-backend/agenta_backend/dbs/postgres/shared/dbas.py @@ -30,10 +30,15 @@ class LifecycleDBA: ) -class UniversionalDBA: +class IdentifierDBA: + __abstract__ = True + + id = Column(UUID(as_uuid=True), nullable=False) + + +class SlugDBA: __abstract__ = True - id = Column(UUID(as_uuid=True), nullable=False, primary_key=True, default=uuid.uuid4) # type: ignore slug = Column(String, nullable=False) @@ -44,7 +49,7 @@ class HeaderDBA: description = Column(String, nullable=True) -class VersionedDBA(LifecycleDBA): +class VersionedDBA: __abstract__ = True slug = Column(String, nullable=False)