diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bf275e1d92bc15e2a48ac0a1dd479ed7c8349ab6..43c0c42914a37f4b0ce1e31ad60cf08c42fc46d5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -50,7 +50,7 @@ integration-test-job: # Runs integration tests with the database MYSQL_DATABASE: "$DB_DATABASE" MYSQL_USER: "$DB_USER" MYSQL_PASSWORD: "$DB_PASSWORD" - - name: $CI_REGISTRY/cmg/clowm/clowm-database:v2.0 + - name: $CI_REGISTRY/cmg/clowm/clowm-database:v2.1 alias: upgrade-db script: - python app/check_database_connection.py @@ -78,7 +78,7 @@ e2e-test-job: # Runs e2e tests on the API endpoints MYSQL_DATABASE: "$DB_DATABASE" MYSQL_USER: "$DB_USER" MYSQL_PASSWORD: "$DB_PASSWORD" - - name: $CI_REGISTRY/cmg/clowm/clowm-database:v2.0 + - name: $CI_REGISTRY/cmg/clowm/clowm-database:v2.1 alias: upgrade-db script: - python app/check_database_connection.py diff --git a/app/crud/crud_bucket.py b/app/crud/crud_bucket.py index 266041bae8b6961b8a6a0ea3f35fc94d935ef424..17cc10995fdea6f1e38611491e3e4d383715c930 100644 --- a/app/crud/crud_bucket.py +++ b/app/crud/crud_bucket.py @@ -61,13 +61,13 @@ class CRUDBucket: .where(BucketPermission.permissions == BucketPermission.Permission.READWRITE) # check READWRITE Permission .where( # check 'form' timestamp is no violated or_( - func.datediff(func.now(), BucketPermission.from_) >= 0, + func.UNIX_TIMESTAMP() >= BucketPermission.from_, BucketPermission.from_ == None, # noqa:E711 ) ) .where( # check 'to' timestamp is no violated or_( - func.datediff(func.now(), BucketPermission.to) <= 0, + func.UNIX_TIMESTAMP() <= BucketPermission.to, BucketPermission.to == None, # noqa:E711 ) ) diff --git a/app/crud/crud_workflow.py b/app/crud/crud_workflow.py index af8fa55194d04b6a54980647acb005552286d4b0..dcd04a143f5b60a45f4b7b4860268da50d123db2 100644 --- a/app/crud/crud_workflow.py +++ b/app/crud/crud_workflow.py @@ -113,7 +113,7 @@ class CRUDWorkflow: """ wid = workflow_id.bytes if isinstance(workflow_id, UUID) else workflow_id stmt = ( - select(cast(WorkflowExecution.start_time, Date).label("day"), func.count()) + select(cast(func.FROM_UNIXTIME(WorkflowExecution.start_time), Date).label("day"), func.count()) .select_from(WorkflowExecution) .join(WorkflowVersion) .where(WorkflowVersion._workflow_id == wid) diff --git a/app/crud/crud_workflow_execution.py b/app/crud/crud_workflow_execution.py index 725b4a76d0c9427aad6fc59f1b959795a22f3a87..5c0f931135f88e01afc3a66a9509fc4095e8100a 100644 --- a/app/crud/crud_workflow_execution.py +++ b/app/crud/crud_workflow_execution.py @@ -2,7 +2,7 @@ from typing import List, Optional, Sequence, Union from uuid import UUID from clowmdb.models import WorkflowExecution -from sqlalchemy import delete, or_, select, text, update +from sqlalchemy import delete, func, or_, select, update from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import joinedload @@ -153,7 +153,7 @@ class CRUDWorkflowExecution: stmt = ( update(WorkflowExecution) .where(WorkflowExecution._execution_id == eid) - .values(status=status.name, end_time=text("CURRENT_TIMESTAMP")) + .values(status=status.name, end_time=func.UNIX_TIMESTAMP()) ) await db.execute(stmt) await db.commit() diff --git a/app/git_repository/github.py b/app/git_repository/github.py index cf2200237281da3cd48b877ab8ea101049aa32aa..8c8a389b37a5397232f9452eb106cad57674313b 100644 --- a/app/git_repository/github.py +++ b/app/git_repository/github.py @@ -77,4 +77,4 @@ class GitHubRepository(GitRepository): def __repr__(self) -> str: url = AnyHttpUrl.build(scheme="https", host="github.com", path="/".join([self.account, self.repository])) - return f"GitHub(repo={url} commit={self.commit}))" + return f"GitHub(repo={url} commit={self.commit})" diff --git a/app/schemas/workflow_execution.py b/app/schemas/workflow_execution.py index 3e8df21bf1e7a28e38ee8f7cc05f3e8bb9e3ac21..c8fa85fd566885336980b19549f8c51b3c52c1ce 100644 --- a/app/schemas/workflow_execution.py +++ b/app/schemas/workflow_execution.py @@ -41,11 +41,15 @@ class WorkflowExecutionOut(_BaseWorkflowExecution): user_id: str = Field( ..., description="UID of user who started the workflow", examples=["28c5353b8bb34984a8bd4169ba94c606"] ) - start_time: datetime = Field( - ..., description="Start time of the workflow execution", examples=[datetime(year=2023, month=1, day=1)] + start_time: int = Field( + ..., + description="Start time of the workflow execution as UNIX timestamp", + examples=[round(datetime(year=2023, month=1, day=1).timestamp())], ) - end_time: Optional[datetime] = Field( - None, description="End time of the workflow execution", examples=[datetime(year=2023, month=1, day=1)] + end_time: Optional[int] = Field( + None, + description="End time of the workflow execution as UNIX timestamp", + examples=[round(datetime(year=2023, month=1, day=1).timestamp())], ) status: WorkflowExecution.WorkflowExecutionStatus = Field( ..., diff --git a/app/schemas/workflow_version.py b/app/schemas/workflow_version.py index b86b86dfb16e23a24031507018ee5a4c33863ff6..bd770af393e67fbbc5dc800fd447f23a8472bd65 100644 --- a/app/schemas/workflow_version.py +++ b/app/schemas/workflow_version.py @@ -36,10 +36,10 @@ class WorkflowVersion(WorkflowVersionStatus): description="URL of the icon for this workflow version", examples=[f"{settings.OBJECT_GATEWAY_URI}{settings.ICON_BUCKET}/{uuid4().hex}.png"], ) - created_at: datetime = Field( + created_at: int = Field( ..., - description="Timestamp when the version was created", - examples=[datetime(year=2023, month=1, day=1)], + description="Timestamp when the version was created as UNIX timestamp", + examples=[round(datetime(year=2023, month=1, day=1).timestamp())], ) @staticmethod diff --git a/app/tests/utils/bucket.py b/app/tests/utils/bucket.py index 0ff7b82b782caaf99cf3d4443253fa7dceba5097..ccc5835d9b14e7297d370b2ba6d7574188315aa7 100644 --- a/app/tests/utils/bucket.py +++ b/app/tests/utils/bucket.py @@ -66,7 +66,12 @@ async def add_permission_for_bucket( The file prefix for the permission. """ perm = BucketPermission( - user_id=uid, bucket_name=bucket_name, from_=from_, to=to, permissions=permission.name, file_prefix=file_prefix + user_id=uid, + bucket_name=bucket_name, + from_=round(from_.timestamp()) if from_ is not None else None, + to=round(to.timestamp()) if to is not None else None, + permissions=permission.name, + file_prefix=file_prefix, ) db.add(perm) await db.commit() diff --git a/app/tests/utils/utils.py b/app/tests/utils/utils.py index 613d5bd96eda466b459ece9d2849b010ccd69ce3..84d22191caa825f3b94b055feecfe8f07f0da588 100644 --- a/app/tests/utils/utils.py +++ b/app/tests/utils/utils.py @@ -1,7 +1,6 @@ import random import string -from datetime import datetime -from typing import Any, Dict, Optional +from typing import Dict import httpx from fastapi import status @@ -57,26 +56,6 @@ def random_ipv4_string() -> str: return ".".join(str(random.randint(0, 255)) for _ in range(4)) -def json_datetime_converter(obj: Any) -> Optional[str]: - """ - Helper function for the json converter to covert the object into a string format if it is a datetime object.\n - Parse a datetime object into the format YYYY-MM-DDTHH:MM:SS, e.g. 2022-01-01T00:00:00 - - Parameters - ---------- - obj : Any - Object to try convert as a datetime object. - - Returns - ------- - time : str | None - The str representation of a datetime object, None otherwise - """ - if isinstance(obj, datetime): - return obj.strftime("%Y-%m-%dT%H:%M:%S") - return None - - def handle_http_request(request: httpx.Request, raise_error: bool = False) -> httpx.Response: """ Handler for a mock HTTP request. Forwards it to the appropriate handler based on the requested URL. diff --git a/requirements.txt b/requirements.txt index d9c606a7891ade202c350788c958bef2e8923c71..0d76968e17ee090ed97197838eba54ef125dc9ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ --extra-index-url https://gitlab.ub.uni-bielefeld.de/api/v4/projects/5493/packages/pypi/simple -clowmdb>=2.0.0,<2.1.0 +clowmdb>=2.1.0,<2.2.0 # Webserver packages anyio>=3.7.0,<3.8.0