workspace database table updates

This commit is contained in:
rushtehrani
2020-04-26 11:27:18 -07:00
parent 27c586560b
commit 151bf47dba
4 changed files with 29 additions and 22 deletions

View File

@@ -1,15 +1,17 @@
-- +goose Up -- +goose Up
CREATE TABLE workspace_templates CREATE TABLE workspace_templates
( (
id serial PRIMARY KEY, id serial PRIMARY KEY,
uid varchar(36) UNIQUE NOT NULL CHECK(uid <> ''), uid varchar(36) UNIQUE NOT NULL CHECK(uid <> ''),
name text NOT NULL CHECK(name <> ''), name text NOT NULL CHECK(name <> ''),
namespace varchar(36) NOT NULL, namespace varchar(36) NOT NULL,
is_archived boolean DEFAULT false, is_archived boolean DEFAULT false,
workflow_template_id integer NOT NULL REFERENCES workflow_templates ON DELETE CASCADE,
-- auditing info -- auditing info
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'), created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
modified_at timestamp modified_at timestamp
); );
CREATE UNIQUE INDEX workspace_templates_name_namespace_key ON workspace_templates (name, namespace) WHERE is_archived = false; CREATE UNIQUE INDEX workspace_templates_name_namespace_key ON workspace_templates (name, namespace) WHERE is_archived = false;

View File

@@ -1,15 +1,15 @@
-- +goose Up -- +goose Up
CREATE TABLE workspace_template_versions CREATE TABLE workspace_template_versions
( (
id serial PRIMARY KEY, id serial PRIMARY KEY,
workspace_template_id integer NOT NULL REFERENCES workspace_templates ON DELETE CASCADE, workspace_template_id integer NOT NULL REFERENCES workspace_templates ON DELETE CASCADE,
version integer NOT NULL, version integer NOT NULL,
manifest text NOT NULL, manifest text NOT NULL,
is_latest boolean DEFAULT false, is_latest boolean DEFAULT false,
-- auditing info -- auditing info
created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'), created_at timestamp NOT NULL DEFAULT (NOW() at time zone 'utc'),
modified_at timestamp modified_at timestamp
); );
-- +goose Down -- +goose Down

View File

@@ -73,6 +73,8 @@ func (c *Client) createWorkflowTemplate(namespace string, workflowTemplate *Work
return nil, err return nil, err
} }
workflowTemplate.Version = versionUnix
return workflowTemplate, nil return workflowTemplate, nil
} }

View File

@@ -339,36 +339,39 @@ func (c *Client) createWorkspaceTemplate(namespace string, workspaceTemplate *Wo
return nil, err return nil, err
} }
workspaceTemplate.Version = workspaceTemplate.WorkflowTemplate.Version
err = sb.Insert("workspace_templates"). err = sb.Insert("workspace_templates").
SetMap(sq.Eq{ SetMap(sq.Eq{
"uid": uid, "uid": uid,
"name": workspaceTemplate.Name, "name": workspaceTemplate.Name,
"namespace": namespace, "namespace": namespace,
"workflow_template_id": workspaceTemplate.WorkflowTemplate.ID,
}). }).
Suffix("RETURNING id"). Suffix("RETURNING id").
RunWith(tx). RunWith(tx).
QueryRow().Scan(&workspaceTemplate.ID) QueryRow().Scan(&workspaceTemplate.ID)
if err != nil { if err != nil {
_, err := c.archiveWorkflowTemplate(namespace, workspaceTemplate.WorkflowTemplate.UID)
return nil, err return nil, err
} }
_, err = sb.Insert("workspace_template_versions"). _, err = sb.Insert("workspace_template_versions").
SetMap(sq.Eq{ SetMap(sq.Eq{
"workspace_template_id": workspaceTemplate.ID, "version": workspaceTemplate.Version,
"version": workspaceTemplate.WorkflowTemplate.Version,
"is_latest": true, "is_latest": true,
"manifest": workspaceTemplate.Manifest, "manifest": workspaceTemplate.Manifest,
"workspace_template_id": workspaceTemplate.ID,
}). }).
RunWith(tx). RunWith(tx).
Exec() Exec()
if err != nil { if err != nil {
_, err := c.archiveWorkflowTemplate(namespace, workspaceTemplate.WorkflowTemplate.UID)
return nil, err return nil, err
} }
if err = tx.Commit(); err != nil { if err = tx.Commit(); err != nil {
//if err := c.ArgoprojV1alpha1().WorkflowTemplates(namespace).Delete(workspaceTemplate.WorkflowTemplate.Name, &metav1.DeleteOptions{}); err != nil { _, err := c.archiveWorkflowTemplate(namespace, workspaceTemplate.WorkflowTemplate.UID)
// log.Printf("Unable to delete argo workflow template")
//}
return nil, err return nil, err
} }