Skip to content

Commit

Permalink
chores(deps): upgrade umzug to 3.4.0 (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Dec 14, 2023
1 parent 200b915 commit a3ee284
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 140 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@storybook/addons": "^6.5.13",
"@storybook/preact": "^6.5.13",
"@testing-library/dom": "^5.4.0",
"@types/bluebird": "^3.5.42",
"@types/body-parser": "^1.17.0",
"@types/compression": "^1.0.1",
"@types/cron": "^1.7.2",
Expand All @@ -50,7 +51,6 @@
"@types/node": "^11.13.2",
"@types/plotly.js": "^1.44.9",
"@types/tmp": "^0.1.0",
"@types/umzug": "^2.2.2",
"@types/uuid": "^8.3.0",
"@types/yargs": "^12.0.8",
"@types/yargs-parser": "^11.0.0",
Expand Down
25 changes: 17 additions & 8 deletions packages/cli/test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/* eslint-env jest */

const assert = require('assert');
const path = require('path');
const os = require('os');
const fs = require('fs');
Expand All @@ -25,6 +26,17 @@ const {

jest.setTimeout(120e3);

async function fetchJson(url) {
const response = await fetch(url);
const text = await response.text();
if (text[0] === '<') {
// Yes, print it also. Because Jest loves to trim error messages.
console.error(`Got a bad response, expected JSON but saw:\n\n${text}`);
assert.fail(`Got a bad response, expected JSON but saw:\n\n${text}`);
}
return JSON.parse(text);
}

describe('Lighthouse CI CLI', () => {
const rcFile = path.join(__dirname, 'fixtures/lighthouserc.json');
const rcMatrixFile = path.join(__dirname, 'fixtures/lighthouserc-matrix.json');
Expand Down Expand Up @@ -53,8 +65,7 @@ describe('Lighthouse CI CLI', () => {

describe('server', () => {
it('should accept requests', async () => {
const response = await fetch(`http://localhost:${server.port}/v1/projects`);
const projects = await response.json();
const projects = await fetchJson(`http://localhost:${server.port}/v1/projects`);
expect(projects).toEqual([]);
});
});
Expand Down Expand Up @@ -246,11 +257,10 @@ describe('Lighthouse CI CLI', () => {

it('should have saved lhrs to the API', async () => {
const [projectId, buildId, runAId, runBId] = uuids;
const response = await fetch(

const runs = await fetchJson(
`http://localhost:${server.port}/v1/projects/${projectId}/builds/${buildId}/runs`
);

const runs = await response.json();
expect(runs.map(run => run.id)).toEqual([runBId, runAId]);
expect(runs.map(run => run.url)).toEqual([
'http://localhost:PORT/app/', // make sure we replaced the port
Expand All @@ -264,11 +274,10 @@ describe('Lighthouse CI CLI', () => {

it('should have sealed the build', async () => {
const [projectId, buildId] = uuids;
const response = await fetch(

const build = await fetchJson(
`http://localhost:${server.port}/v1/projects/${projectId}/builds/${buildId}`
);

const build = await response.json();
expect(build).toMatchObject({lifecycle: 'sealed'});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"express-basic-auth": "^1.2.0",
"morgan": "^1.9.1",
"sequelize": "^6.35.2",
"umzug": "^2.2.0",
"umzug": "^3.4.0",
"uuid": "^8.3.1"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/api/express-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module.exports = {
.catch(err => {
if (err.name === 'SequelizeDatabaseError' && err.message.includes('value too long')) {
next(new E422(err.message));
} else if (err.name === 'SequelizeDatabaseError') {
next(new Error(err.message + '\n' + err.stack));
} else {
next(err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/
'use strict';

const Sequelize = require('sequelize');

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
* @param {LHCI.ServerCommand.StorageOptions} options
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async (queryInterface, Sequelize, options) => {
up: async ({queryInterface, options}) => {
await queryInterface.createTable('projects', {
id: {type: Sequelize.UUID(), primaryKey: true},
name: {type: Sequelize.STRING(40)},
Expand Down Expand Up @@ -58,9 +58,9 @@ module.exports = {
});
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.dropTable('statistics');
await queryInterface.dropTable('runs');
await queryInterface.dropTable('builds');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/
'use strict';

const Sequelize = require('sequelize');

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async (queryInterface, Sequelize) => {
up: async ({queryInterface}) => {
await queryInterface.addColumn('projects', 'token', {type: Sequelize.UUID()});
await queryInterface.bulkUpdate(
'projects',
Expand All @@ -22,9 +23,9 @@ module.exports = {
);
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.removeColumn('projects', 'token');
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
*/
'use strict';

const Sequelize = require('sequelize');

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async (queryInterface, Sequelize) => {
up: async ({queryInterface}) => {
await queryInterface.addColumn('builds', 'committedAt', {type: Sequelize.DATE(6)});
await queryInterface.addColumn('builds', 'ancestorCommittedAt', {type: Sequelize.DATE(6)});
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.removeColumn('builds', 'committedAt');
await queryInterface.removeColumn('builds', 'ancestorCommittedAt');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/
'use strict';

const Sequelize = require('sequelize');

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async (queryInterface, Sequelize) => {
up: async ({queryInterface}) => {
await queryInterface.addColumn('projects', 'slug', {type: Sequelize.STRING(40)});
await queryInterface.bulkUpdate(
'projects',
Expand All @@ -28,9 +29,9 @@ module.exports = {
});
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.removeIndex('projects', 'projects_unique_slug');
await queryInterface.removeColumn('projects', 'slug');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/
'use strict';

const Sequelize = require('sequelize');

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async (queryInterface, Sequelize) => {
up: async ({queryInterface}) => {
await queryInterface.addColumn('statistics', 'version', {type: Sequelize.DECIMAL(8, 2)});
await queryInterface.bulkUpdate(
'statistics',
Expand All @@ -22,9 +23,9 @@ module.exports = {
);
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.removeColumn('statistics', 'version');
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
*/
'use strict';

const Sequelize = require('sequelize');
const {hashAdminToken, generateAdminToken} = require('../../auth.js');

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async (queryInterface, Sequelize) => {
up: async ({queryInterface}) => {
await queryInterface.addColumn('projects', 'adminToken', {type: Sequelize.STRING(64)});
await queryInterface.bulkUpdate(
'projects',
Expand All @@ -26,9 +26,9 @@ module.exports = {
);
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.removeColumn('projects', 'adminToken');
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/
'use strict';

const Sequelize = require('sequelize');

/* eslint-disable new-cap */

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {typeof import('sequelize')} Sequelize
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async (queryInterface, Sequelize) => {
up: async ({queryInterface}) => {
await queryInterface.addColumn('projects', 'baseBranch', {type: Sequelize.STRING(80)});
await queryInterface.bulkUpdate(
'projects',
Expand All @@ -22,9 +23,9 @@ module.exports = {
);
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.removeColumn('projects', 'baseBranch');
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

module.exports = {
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
up: async queryInterface => {
up: async ({queryInterface}) => {
await queryInterface.addIndex('builds', ['projectId', 'lifecycle', 'createdAt']);
await queryInterface.addIndex('builds', ['projectId', 'hash', 'createdAt']);
await queryInterface.addIndex('builds', ['projectId', 'branch', 'hash', 'createdAt']);
Expand All @@ -18,9 +18,9 @@ module.exports = {
await queryInterface.addIndex('statistics', ['projectId', 'buildId', 'url', 'name']);
},
/**
* @param {import('sequelize').QueryInterface} queryInterface
* @param {{queryInterface: import('sequelize').QueryInterface, options: LHCI.ServerCommand.StorageOptions}} _
*/
down: async queryInterface => {
down: async ({queryInterface}) => {
await queryInterface.removeIndex('builds', ['projectId', 'lifecycle']);
await queryInterface.removeIndex('builds', ['projectId', 'hash']);
await queryInterface.removeIndex('builds', ['projectId', 'branch', 'hash']);
Expand Down
33 changes: 24 additions & 9 deletions packages/server/src/api/storage/sql/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
'use strict';

const path = require('path');
const log = require('debug')('lhci:server:sql');
const logVerbose = require('debug')('lhci:server:sql:verbose');
const path = require('path');
const uuid = require('uuid');
const Umzug = require('umzug');
const {Umzug, SequelizeStorage} = require('umzug');
const {Sequelize, Op} = require('sequelize');
const {omit, padEnd} = require('@lhci/utils/src/lodash.js');
const {hashAdminToken, generateAdminToken} = require('../auth.js');
Expand Down Expand Up @@ -133,15 +133,29 @@ function createSequelize(options) {
*/
function createUmzug(sequelize, options) {
return new Umzug({
logging: /** @param {*} msg */ msg => logVerbose('[umzug]', msg),
storage: 'sequelize',
storageOptions: {
sequelize: /** @type {*} */ (sequelize),
tableName: options.sqlMigrationOptions && options.sqlMigrationOptions.tableName,
logger: {
debug: msg => logVerbose('[umzug]', msg),
warn: msg => logVerbose('[umzug]', msg),
error: msg => logVerbose('[umzug]', msg),
info: msg => logVerbose('[umzug]', msg),
},
storage: new SequelizeStorage({
sequelize,
tableName: options.sqlMigrationOptions && options.sqlMigrationOptions.tableName,
}),
context: {queryInterface: sequelize.getQueryInterface(), options},
migrations: {
path: path.join(__dirname, 'migrations'),
params: [sequelize.getQueryInterface(), Sequelize, options],
glob: path.posix.join(__dirname.replaceAll('\\', '/'), 'migrations/*.js'),
resolve: ({name, path, context}) => {
if (!path) throw new Error('unexpected missing path');

const migration = require(path);
return {
name,
up: async () => migration.up(context),
down: async () => migration.down(context),
};
},
},
});
}
Expand Down Expand Up @@ -377,6 +391,7 @@ class SqlStorageMethod {
*/
async _createProject(unsavedProject) {
const {projectModel} = this._sql();
if (typeof unsavedProject.name !== 'string') throw new E422('Project name missing');
if (unsavedProject.name.length < 4) throw new E422('Project name too short');
const projectId = uuid.v4();
const adminToken = generateAdminToken();
Expand Down
Loading

0 comments on commit a3ee284

Please sign in to comment.