From 8e36a07ede8bd8d61bf10a1de8b42af8c9c34bd5 Mon Sep 17 00:00:00 2001 From: Andrey Melnikov Date: Fri, 26 Feb 2021 10:19:22 -0800 Subject: [PATCH] feat: updated workflow/workspace fields to allow some related field queries. --- pkg/workflow_execution.go | 13 ++++++++++--- pkg/workspace.go | 23 +++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/pkg/workflow_execution.go b/pkg/workflow_execution.go index 603c3cb1..dc5e78bb 100644 --- a/pkg/workflow_execution.go +++ b/pkg/workflow_execution.go @@ -2390,12 +2390,19 @@ func (c *Client) UpdateWorkflowExecutionMetrics(namespace, uid string, metrics M // ListWorkflowExecutionsField loads all of the distinct field values for workflow executions func (c *Client) ListWorkflowExecutionsField(namespace, field string) (value []string, err error) { - if field != "name" { + columnName := "" + + switch field { + case "name": + columnName = "we.name" + break + case "templateName": + columnName = "wt.name" + break + default: return nil, fmt.Errorf("unsupported field '%v'", field) } - columnName := fmt.Sprintf("we.%v", field) - sb := sb.Select(columnName). Distinct(). From("workflow_executions we"). diff --git a/pkg/workspace.go b/pkg/workspace.go index 21063184..53428112 100644 --- a/pkg/workspace.go +++ b/pkg/workspace.go @@ -985,18 +985,29 @@ func (c *Client) GetWorkspaceContainerLogs(namespace, uid, containerName string, // ListWorkspacesField loads all of the distinct field values for workspaces func (c *Client) ListWorkspacesField(namespace, field string) (value []string, err error) { - if field != "name" { + columnName := "" + + switch field { + case "name": + columnName = "w.name" + break + case "templateName": + columnName = "wt.name" + break + default: return nil, fmt.Errorf("unsupported field '%v'", field) } - columnName := fmt.Sprintf("w.%v", field) - sb := sb.Select(columnName). Distinct(). From("workspaces w"). - Where(sq.Eq{ - "w.namespace": namespace, - }).OrderBy(columnName) + Join("workspace_templates wt ON w.workspace_template_id = wt.id"). + Where(sq.And{ + sq.Eq{ + "w.namespace": namespace, + }, sq.NotEq{ + "w.phase": WorkspaceTerminated, + }}).OrderBy(columnName) err = c.DB.Selectx(&value, sb)