From cbd563a6e863d6f47732b40902d7abed51c2e2bb Mon Sep 17 00:00:00 2001 From: Dayanand Sagar Date: Thu, 29 Aug 2024 10:36:08 -0700 Subject: [PATCH] feat(3171): Persist pipeline template workflowGraph in a new column (BREAKING CHANGE) (#575) --- config/pipelineTemplate.js | 4 +--- ...0607152947-add_column_state_to_pipeline.js | 4 ++-- models/pipelineTemplateVersions.js | 11 +++++++--- ...ipelineTemplateVersions.get.allFields.yaml | 20 +++++++++---------- test/data/pipelineTemplateVersions.yaml | 11 ++++++++++ 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/config/pipelineTemplate.js b/config/pipelineTemplate.js index 11afac1a..e092aa81 100644 --- a/config/pipelineTemplate.js +++ b/config/pipelineTemplate.js @@ -6,7 +6,6 @@ const Annotations = require('./annotations'); const Parameters = require('./parameters'); const Template = require('./template'); const Regex = require('./regex'); -const WorkflowGraph = require('./workflowGraph'); const SCHEMA_CONFIG = Joi.object() .keys({ @@ -16,8 +15,7 @@ const SCHEMA_CONFIG = Joi.object() annotations: Annotations.annotations, cache: BaseSchema.cache, subscribe: BaseSchema.subscribe, - stages: BaseSchema.stages, - workflowGraph: WorkflowGraph.workflowGraph + stages: BaseSchema.stages }) .unknown(false); diff --git a/migrations/20220607152947-add_column_state_to_pipeline.js b/migrations/20220607152947-add_column_state_to_pipeline.js index 0f05f237..22f09f0d 100644 --- a/migrations/20220607152947-add_column_state_to_pipeline.js +++ b/migrations/20220607152947-add_column_state_to_pipeline.js @@ -12,8 +12,8 @@ module.exports = { table, 'state', { - type: Sequelize.STRING(10), - defaultValue: 'ACTIVE', + type: Sequelize.TEXT, + defaultValue: '{}', allowNull: false }, { transaction } diff --git a/models/pipelineTemplateVersions.js b/models/pipelineTemplateVersions.js index 56e54ace..d38d8481 100644 --- a/models/pipelineTemplateVersions.js +++ b/models/pipelineTemplateVersions.js @@ -4,6 +4,7 @@ const Joi = require('joi'); const mutate = require('../lib/mutate'); const pipelineTemplateVersions = require('../config/pipelineTemplate'); const JobTemplateConfig = require('../config/template'); +const WorkflowGraph = require('../config/workflowGraph'); const templateId = require('./templateMeta').base.extract('id'); const MODEL = { @@ -17,6 +18,10 @@ const MODEL = { .max(32) .description('When this template was created') .example('2038-01-19T03:14:08.131Z') + .required(), + workflowGraph: WorkflowGraph.workflowGraph + .description('Graph representation of the workflow') + .default('{"nodes": [],"edges":[]}') .required() }; @@ -43,9 +48,9 @@ module.exports = { * @property get * @type {Joi} */ - get: Joi.object(mutate(MODEL, ['id', 'templateId', 'version'], ['description', 'config', 'createTime'])).label( - 'Get Template' - ), + get: Joi.object( + mutate(MODEL, ['id', 'templateId', 'version'], ['description', 'config', 'createTime', 'workflowGraph']) + ).label('Get Template'), /** * List of fields that determine a unique row diff --git a/test/data/pipelineTemplateVersions.get.allFields.yaml b/test/data/pipelineTemplateVersions.get.allFields.yaml index 99805f2c..96fd4ce8 100644 --- a/test/data/pipelineTemplateVersions.get.allFields.yaml +++ b/test/data/pipelineTemplateVersions.get.allFields.yaml @@ -21,15 +21,15 @@ config: user: value: sd-bot description: User running build - workflowGraph: - nodes: - - name: ~commit - - name: main - - name: publish - edges: - - src: ~commit - dest: main - - src: main - dest: publish +workflowGraph: + nodes: + - name: ~commit + - name: main + - name: publish + edges: + - src: ~commit + dest: main + - src: main + dest: publish createTime: "2038-01-19T03:14:08.131Z" diff --git a/test/data/pipelineTemplateVersions.yaml b/test/data/pipelineTemplateVersions.yaml index 23f22e23..170423dd 100644 --- a/test/data/pipelineTemplateVersions.yaml +++ b/test/data/pipelineTemplateVersions.yaml @@ -9,4 +9,15 @@ config: steps: - init: npm install - test: npm test + publish: + steps: + - init: npm install + - publish: npm publish +workflowGraph: + nodes: + - name: main + - name: publish + edges: + - src: main + dest: publish createTime: "2038-01-19T03:14:08.131Z"