Skip to content

Commit

Permalink
feat(3171): Persist pipeline template workflowGraph in a new column. …
Browse files Browse the repository at this point in the history
…BREAKING CHANGE: adding new column to pipelineTemplateVersions (#577)
  • Loading branch information
sagar1312 authored Aug 29, 2024
1 parent b6a45db commit bf29482
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 16 deletions.
4 changes: 1 addition & 3 deletions config/pipelineTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const prefix = process.env.DATASTORE_SEQUELIZE_PREFIX || '';
const table = `${prefix}pipelineTemplateVersions`;

module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn(
table,
'workflowGraph',
{
type: Sequelize.TEXT,
defaultValue: '{"nodes": [],"edges":[]}',
allowNull: false
},
{ transaction }
);
});
}
};
11 changes: 8 additions & 3 deletions models/pipelineTemplateVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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()
};

Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions test/data/pipelineTemplateVersions.get.allFields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 11 additions & 0 deletions test/data/pipelineTemplateVersions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit bf29482

Please sign in to comment.