mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-07 22:50:53 +08:00
workspace database table updates
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE workspace_templates
|
||||
(
|
||||
id serial PRIMARY KEY,
|
||||
uid varchar(36) UNIQUE NOT NULL CHECK(uid <> ''),
|
||||
name text NOT NULL CHECK(name <> ''),
|
||||
namespace varchar(36) NOT NULL,
|
||||
is_archived boolean DEFAULT false,
|
||||
id serial PRIMARY KEY,
|
||||
uid varchar(36) UNIQUE NOT NULL CHECK(uid <> ''),
|
||||
name text NOT NULL CHECK(name <> ''),
|
||||
namespace varchar(36) NOT NULL,
|
||||
is_archived boolean DEFAULT false,
|
||||
|
||||
workflow_template_id integer NOT NULL REFERENCES workflow_templates ON DELETE CASCADE,
|
||||
|
||||
-- auditing info
|
||||
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
|
||||
modified_at timestamp
|
||||
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
|
||||
modified_at timestamp
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX workspace_templates_name_namespace_key ON workspace_templates (name, namespace) WHERE is_archived = false;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE workspace_template_versions
|
||||
(
|
||||
id serial PRIMARY KEY,
|
||||
workspace_template_id integer NOT NULL REFERENCES workspace_templates ON DELETE CASCADE,
|
||||
version integer NOT NULL,
|
||||
manifest text NOT NULL,
|
||||
is_latest boolean DEFAULT false,
|
||||
id serial PRIMARY KEY,
|
||||
workspace_template_id integer NOT NULL REFERENCES workspace_templates ON DELETE CASCADE,
|
||||
version integer NOT NULL,
|
||||
manifest text NOT NULL,
|
||||
is_latest boolean DEFAULT false,
|
||||
|
||||
-- auditing info
|
||||
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
|
||||
modified_at timestamp
|
||||
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
|
||||
modified_at timestamp
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
|
@@ -73,6 +73,8 @@ func (c *Client) createWorkflowTemplate(namespace string, workflowTemplate *Work
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workflowTemplate.Version = versionUnix
|
||||
|
||||
return workflowTemplate, nil
|
||||
}
|
||||
|
||||
|
@@ -339,36 +339,39 @@ func (c *Client) createWorkspaceTemplate(namespace string, workspaceTemplate *Wo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workspaceTemplate.Version = workspaceTemplate.WorkflowTemplate.Version
|
||||
|
||||
err = sb.Insert("workspace_templates").
|
||||
SetMap(sq.Eq{
|
||||
"uid": uid,
|
||||
"name": workspaceTemplate.Name,
|
||||
"namespace": namespace,
|
||||
"uid": uid,
|
||||
"name": workspaceTemplate.Name,
|
||||
"namespace": namespace,
|
||||
"workflow_template_id": workspaceTemplate.WorkflowTemplate.ID,
|
||||
}).
|
||||
Suffix("RETURNING id").
|
||||
RunWith(tx).
|
||||
QueryRow().Scan(&workspaceTemplate.ID)
|
||||
if err != nil {
|
||||
_, err := c.archiveWorkflowTemplate(namespace, workspaceTemplate.WorkflowTemplate.UID)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = sb.Insert("workspace_template_versions").
|
||||
SetMap(sq.Eq{
|
||||
"workspace_template_id": workspaceTemplate.ID,
|
||||
"version": workspaceTemplate.WorkflowTemplate.Version,
|
||||
"version": workspaceTemplate.Version,
|
||||
"is_latest": true,
|
||||
"manifest": workspaceTemplate.Manifest,
|
||||
"workspace_template_id": workspaceTemplate.ID,
|
||||
}).
|
||||
RunWith(tx).
|
||||
Exec()
|
||||
if err != nil {
|
||||
_, err := c.archiveWorkflowTemplate(namespace, workspaceTemplate.WorkflowTemplate.UID)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = tx.Commit(); err != nil {
|
||||
//if err := c.ArgoprojV1alpha1().WorkflowTemplates(namespace).Delete(workspaceTemplate.WorkflowTemplate.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
// log.Printf("Unable to delete argo workflow template")
|
||||
//}
|
||||
_, err := c.archiveWorkflowTemplate(namespace, workspaceTemplate.WorkflowTemplate.UID)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user