refactor: use EnumText for WorkflowAppLog.created_from and WorkflowArchiveLog columns (#33954)

This commit is contained in:
tmimmanuel
2026-03-23 18:44:46 +01:00
committed by GitHub
parent f5cc1c8b75
commit 20fc69ae7f
5 changed files with 29 additions and 22 deletions

View File

@@ -705,7 +705,7 @@ class WorkflowAppGenerateTaskPipeline(GraphRuntimeStateSupport):
app_id=self._application_generate_entity.app_config.app_id, app_id=self._application_generate_entity.app_config.app_id,
workflow_id=self._workflow.id, workflow_id=self._workflow.id,
workflow_run_id=workflow_run_id, workflow_run_id=workflow_run_id,
created_from=created_from.value, created_from=created_from,
created_by_role=self._created_by_role, created_by_role=self._created_by_role,
created_by=self._user_id, created_by=self._user_id,
) )

View File

@@ -1221,7 +1221,9 @@ class WorkflowAppLog(TypeBase):
app_id: Mapped[str] = mapped_column(StringUUID) app_id: Mapped[str] = mapped_column(StringUUID)
workflow_id: Mapped[str] = mapped_column(StringUUID, nullable=False) workflow_id: Mapped[str] = mapped_column(StringUUID, nullable=False)
workflow_run_id: Mapped[str] = mapped_column(StringUUID) workflow_run_id: Mapped[str] = mapped_column(StringUUID)
created_from: Mapped[str] = mapped_column(String(255), nullable=False) created_from: Mapped[WorkflowAppLogCreatedFrom] = mapped_column(
EnumText(WorkflowAppLogCreatedFrom, length=255), nullable=False
)
created_by_role: Mapped[CreatorUserRole] = mapped_column(EnumText(CreatorUserRole, length=255), nullable=False) created_by_role: Mapped[CreatorUserRole] = mapped_column(EnumText(CreatorUserRole, length=255), nullable=False)
created_by: Mapped[str] = mapped_column(StringUUID, nullable=False) created_by: Mapped[str] = mapped_column(StringUUID, nullable=False)
created_at: Mapped[datetime] = mapped_column( created_at: Mapped[datetime] = mapped_column(
@@ -1301,10 +1303,14 @@ class WorkflowArchiveLog(TypeBase):
log_id: Mapped[str | None] = mapped_column(StringUUID, nullable=True) log_id: Mapped[str | None] = mapped_column(StringUUID, nullable=True)
log_created_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) log_created_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
log_created_from: Mapped[str | None] = mapped_column(String(255), nullable=True) log_created_from: Mapped[WorkflowAppLogCreatedFrom | None] = mapped_column(
EnumText(WorkflowAppLogCreatedFrom, length=255), nullable=True
)
run_version: Mapped[str] = mapped_column(String(255), nullable=False) run_version: Mapped[str] = mapped_column(String(255), nullable=False)
run_status: Mapped[str] = mapped_column(String(255), nullable=False) run_status: Mapped[WorkflowExecutionStatus] = mapped_column(
EnumText(WorkflowExecutionStatus, length=255), nullable=False
)
run_triggered_from: Mapped[WorkflowRunTriggeredFrom] = mapped_column( run_triggered_from: Mapped[WorkflowRunTriggeredFrom] = mapped_column(
EnumText(WorkflowRunTriggeredFrom, length=255), nullable=False EnumText(WorkflowRunTriggeredFrom, length=255), nullable=False
) )

View File

@@ -179,7 +179,7 @@ def _record_trigger_failure_log(
app_id=workflow.app_id, app_id=workflow.app_id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from=WorkflowAppLogCreatedFrom.SERVICE_API.value, created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=created_by_role, created_by_role=created_by_role,
created_by=created_by, created_by=created_by,
) )

View File

@@ -27,7 +27,7 @@ from models.human_input import (
HumanInputFormRecipient, HumanInputFormRecipient,
RecipientType, RecipientType,
) )
from models.workflow import WorkflowAppLog, WorkflowPause, WorkflowPauseReason, WorkflowRun from models.workflow import WorkflowAppLog, WorkflowAppLogCreatedFrom, WorkflowPause, WorkflowPauseReason, WorkflowRun
from repositories.entities.workflow_pause import WorkflowPauseEntity from repositories.entities.workflow_pause import WorkflowPauseEntity
from repositories.sqlalchemy_api_workflow_run_repository import ( from repositories.sqlalchemy_api_workflow_run_repository import (
DifyAPISQLAlchemyWorkflowRunRepository, DifyAPISQLAlchemyWorkflowRunRepository,
@@ -218,7 +218,7 @@ class TestDeleteRunsWithRelated:
app_id=test_scope.app_id, app_id=test_scope.app_id,
workflow_id=test_scope.workflow_id, workflow_id=test_scope.workflow_id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=test_scope.user_id, created_by=test_scope.user_id,
) )
@@ -278,7 +278,7 @@ class TestCountRunsWithRelated:
app_id=test_scope.app_id, app_id=test_scope.app_id,
workflow_id=test_scope.workflow_id, workflow_id=test_scope.workflow_id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=test_scope.user_id, created_by=test_scope.user_id,
) )

View File

@@ -10,6 +10,7 @@ from sqlalchemy.orm import Session
from dify_graph.entities.workflow_execution import WorkflowExecutionStatus from dify_graph.entities.workflow_execution import WorkflowExecutionStatus
from models import EndUser, Workflow, WorkflowAppLog, WorkflowRun from models import EndUser, Workflow, WorkflowAppLog, WorkflowRun
from models.enums import CreatorUserRole from models.enums import CreatorUserRole
from models.workflow import WorkflowAppLogCreatedFrom
from services.account_service import AccountService, TenantService from services.account_service import AccountService, TenantService
# Delay import of AppService to avoid circular dependency # Delay import of AppService to avoid circular dependency
@@ -221,7 +222,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -357,7 +358,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run_1.id, workflow_run_id=workflow_run_1.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -399,7 +400,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run_2.id, workflow_run_id=workflow_run_2.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -441,7 +442,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run_4.id, workflow_run_id=workflow_run_4.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -521,7 +522,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -627,7 +628,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -732,7 +733,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -860,7 +861,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -902,7 +903,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="web-app", created_from=WorkflowAppLogCreatedFrom.WEB_APP,
created_by_role=CreatorUserRole.END_USER, created_by_role=CreatorUserRole.END_USER,
created_by=end_user.id, created_by=end_user.id,
) )
@@ -1037,7 +1038,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -1125,7 +1126,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -1279,7 +1280,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -1379,7 +1380,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )
@@ -1481,7 +1482,7 @@ class TestWorkflowAppService:
app_id=app.id, app_id=app.id,
workflow_id=workflow.id, workflow_id=workflow.id,
workflow_run_id=workflow_run.id, workflow_run_id=workflow_run.id,
created_from="service-api", created_from=WorkflowAppLogCreatedFrom.SERVICE_API,
created_by_role=CreatorUserRole.ACCOUNT, created_by_role=CreatorUserRole.ACCOUNT,
created_by=account.id, created_by=account.id,
) )