Skip to content

Commit

Permalink
fix(3191): Add templateId and archived index to jobs table (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakanechi authored Sep 9, 2024
1 parent fb4f879 commit d04a702
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions migrations/20240906-add-templateId-and-archive-index-to-builds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable new-cap */

'use strict';

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

module.exports = {
// eslint-disable-next-line no-unused-vars
up: async (queryInterface, Sequelize) => {
await queryInterface.sequelize.transaction(async transaction => {
await queryInterface.removeIndex(table, `${table}_templateId`, { transaction });

await queryInterface.addIndex(table, {
name: `${table}_templateId_archived`,
fields: ['templateId', 'archived'],
transaction
});
});
}
};
2 changes: 1 addition & 1 deletion models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,5 @@ module.exports = {
* @property indexes
* @type {Array}
*/
indexes: [{ fields: ['pipelineId', 'state'] }, { fields: ['state'] }, { fields: ['templateId'] }]
indexes: [{ fields: ['pipelineId', 'state'] }, { fields: ['state'] }, { fields: ['templateId', 'archived'] }]
};
6 changes: 5 additions & 1 deletion test/models/job.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ describe('model job', () => {

describe('indexes', () => {
it('defines the correct indexes', () => {
const expected = [{ fields: ['pipelineId', 'state'] }, { fields: ['state'] }, { fields: ['templateId'] }];
const expected = [
{ fields: ['pipelineId', 'state'] },
{ fields: ['state'] },
{ fields: ['templateId', 'archived'] }
];
const { indexes } = models.job;

expected.forEach(indexName => {
Expand Down

0 comments on commit d04a702

Please sign in to comment.