From 0e5fa148d1b4c240b95914bbeed87943127d0856 Mon Sep 17 00:00:00 2001 From: Abram Date: Tue, 23 Apr 2024 17:43:10 +0100 Subject: [PATCH] Refactor: ensurer revision documents with created_at field is added/modified on point of creation --- agenta-backend/agenta_backend/models/db_models.py | 4 ++-- agenta-backend/agenta_backend/services/db_manager.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/models/db_models.py b/agenta-backend/agenta_backend/models/db_models.py index 26f78e9516..f71b385985 100644 --- a/agenta-backend/agenta_backend/models/db_models.py +++ b/agenta-backend/agenta_backend/models/db_models.py @@ -104,7 +104,7 @@ class AppVariantRevisionsDB(Document): modified_by: Link[UserDB] base: Link[VariantBaseDB] config: ConfigDB - created_at: Optional[datetime] = Field(default=datetime.now()) + created_at: datetime updated_at: Optional[datetime] = Field(default=datetime.now()) class Settings: @@ -131,7 +131,7 @@ class AppEnvironmentRevisionDB(Document): modified_by: Link[UserDB] deployed_app_variant_revision: Optional[PydanticObjectId] deployment: Optional[PydanticObjectId] # reference to deployment - created_at: Optional[datetime] = Field(default=datetime.utcnow()) + created_at: datetime class Settings: name = "environments_revisions" diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index b34b198408..d4da5d31d7 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -404,6 +404,7 @@ async def create_new_app_variant( modified_by=user, base=base, config=config, + created_at=datetime.now() ) await variant_revision.create() @@ -891,6 +892,7 @@ async def add_variant_from_base_and_config( modified_by=user_db, base=base_db, config=config_db, + created_at=datetime.now() ) await variant_revision.create() @@ -1284,6 +1286,7 @@ async def create_environment_revision( environment=environment, revision=environment.revision, modified_by=user, + created_at=datetime.now() ) if kwargs: @@ -1497,6 +1500,7 @@ async def update_variant_parameters( modified_by=user, base=app_variant_db.base, config=config_db, + created_at=datetime.now() ) await variant_revision.save()