Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {

if (detectors.length > 0) {
await queryInterface.bulkInsert('detectors', detectors.map((detector) => ({ name: detector })));
await queryInterface.sequelize.query(DETECTORS_COLUMN_TO_RELATION_TABLE);
await queryInterface.sequelize.query(DETECTORS_COLUMN_TO_RELATION_TABLE, { type: QueryTypes.INSERT });
}
});
},
Expand All @@ -63,6 +63,6 @@ module.exports = {
* Example:
* await queryInterface.dropTable('users');
*/
await queryInterface.sequelize.query(DETECTORS_RELATION_TABLE_TO_COLUMN);
await queryInterface.sequelize.query(DETECTORS_RELATION_TABLE_TO_COLUMN, { type: QueryTypes.UPDATE });
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
name: 'unique_name_run_number_flp_roles',
}, { transaction });

await queryInterface.sequelize.query(TRANSFER_RUN_ID_TO_FLP_ROLES, { transaction });
await queryInterface.sequelize.query(TRANSFER_RUN_ID_TO_FLP_ROLES, { transaction, type: QueryTypes.UPDATE });

await queryInterface.dropTable('flp_runs', { transaction });
}),
Expand All @@ -79,7 +79,7 @@ module.exports = {
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
},
}, { transaction });
await queryInterface.sequelize.query(TRANSFER_RUN_ID_TO_FLP_RUNS, { transaction });
await queryInterface.sequelize.query(TRANSFER_RUN_ID_TO_FLP_RUNS, { transaction, type: QueryTypes.INSERT });
await queryInterface.removeConstraint('flp_roles', 'fk_run_number_flp_roles', { transaction });
await queryInterface.removeConstraint('flp_roles', 'unique_name_run_number_flp_roles', { transaction });
await queryInterface.removeColumn('flp_roles', 'run_number', { transaction });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { QueryTypes } = require('sequelize');

module.exports = {

// eslint-disable-next-line jsdoc/require-jsdoc
Expand Down Expand Up @@ -44,14 +46,14 @@ module.exports = {
SELECT id, "STANDBY", created_at, created_at
FROM environments e
WHERE created_at <> updated_at
`);
`, { type: QueryTypes.INSERT });

// Use updated at to define the current history item
await queryInterface.sequelize.query(`
INSERT INTO environments_history_items(environment_id, status, status_message, created_at, updated_at)
SELECT id, status, status_message, updated_at, updated_at
FROM environments;
`);
`, { type: QueryTypes.INSERT });

await Promise.all([
queryInterface.removeColumn('environments', 'status'),
Expand Down Expand Up @@ -79,7 +81,7 @@ module.exports = {
ON h.environment_id = e.id
SET e.status = h.status, e.status_message = h.status_message, e.updated_at = h.updated_at
ORDER BY h.updated_at DESC
`);
`, { type: QueryTypes.UPDATE });

await queryInterface.dropTable('environments_history_items');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

'use strict';

const { QueryTypes } = require('sequelize');

const { RUN_DEFINITIONS } = require('../../../domain/enums/RunDefinition.js');

const SET_PHYSICS_DEFINITION = `
Expand Down Expand Up @@ -96,12 +98,12 @@ module.exports = {
await queryInterface.addColumn('runs', 'definition', {
type: Sequelize.ENUM(...RUN_DEFINITIONS),
}, { transaction });
await queryInterface.sequelize.query(SET_PHYSICS_DEFINITION, { transaction });
await queryInterface.sequelize.query(SET_COSMICS_DEFINITION, { transaction });
await queryInterface.sequelize.query(SET_TECHNICAL_DEFINITION, { transaction });
await queryInterface.sequelize.query(SET_SYNTHETIC_DEFINITION, { transaction });
await queryInterface.sequelize.query(SET_CALIBRATION_DEFINITION, { transaction });
await queryInterface.sequelize.query(SET_COMMISSIONING_DEFINITION, { transaction });
await queryInterface.sequelize.query(SET_PHYSICS_DEFINITION, { transaction, type: QueryTypes.UPDATE });
await queryInterface.sequelize.query(SET_COSMICS_DEFINITION, { transaction, type: QueryTypes.UPDATE });
await queryInterface.sequelize.query(SET_TECHNICAL_DEFINITION, { transaction, type: QueryTypes.UPDATE });
await queryInterface.sequelize.query(SET_SYNTHETIC_DEFINITION, { transaction, type: QueryTypes.UPDATE });
await queryInterface.sequelize.query(SET_CALIBRATION_DEFINITION, { transaction, type: QueryTypes.UPDATE });
await queryInterface.sequelize.query(SET_COMMISSIONING_DEFINITION, { transaction, type: QueryTypes.UPDATE });
await queryInterface.changeColumn('runs', 'definition', {
type: Sequelize.ENUM(...RUN_DEFINITIONS),
allowNull: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

'use strict';

const { QueryTypes } = require('sequelize');

const ADD_RUN_START_AND_STOP = `
ALTER TABLE runs
ADD COLUMN time_start DATETIME AS (COALESCE(time_trg_start, time_trg_end)) VIRTUAL AFTER time_trg_end,
Expand Down Expand Up @@ -62,14 +64,14 @@ GROUP BY sbr.fill_number;
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(ADD_RUN_START_AND_STOP, { transaction });
await queryInterface.sequelize.query(ADD_STABLE_BEAMS_RUNS_VIEW, { transaction });
await queryInterface.sequelize.query(ADD_FILL_STATISTICS_VIEW, { transaction });
await queryInterface.sequelize.query(ADD_RUN_START_AND_STOP, { transaction, type: QueryTypes.RAW });
await queryInterface.sequelize.query(ADD_STABLE_BEAMS_RUNS_VIEW, { transaction, type: QueryTypes.RAW });
await queryInterface.sequelize.query(ADD_FILL_STATISTICS_VIEW, { transaction, type: QueryTypes.RAW });
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query('DROP VIEW stable_beam_runs', { transaction });
await queryInterface.sequelize.query('DROP VIEW fill_statistics', { transaction });
await queryInterface.sequelize.query('DROP VIEW stable_beam_runs', { transaction, type: QueryTypes.RAW });
await queryInterface.sequelize.query('DROP VIEW fill_statistics', { transaction, type: QueryTypes.RAW });
await queryInterface.removeColumn('runs', 'time_start', { transaction });
await queryInterface.removeColumn('runs', 'time_end', { transaction });
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

'use strict';

const { QueryTypes } = require('sequelize');

const { RUN_CALIBRATION_STATUS, RunCalibrationStatus } = require('../../../domain/enums/RunCalibrationStatus.js');
const { RunDefinition } = require('../../../domain/enums/RunDefinition.js');

Expand All @@ -32,12 +34,12 @@ module.exports = {
await queryInterface.addColumn('runs', 'calibration_status', {
type: Sequelize.ENUM(...RUN_CALIBRATION_STATUS),
}, { transaction });
await queryInterface.sequelize.query(UPDATE_CALIBRATION_STATUS, { transaction });
await queryInterface.sequelize.query(ADD_CALIBRATION_STATUS_CONSTRAINT, { transaction });
await queryInterface.sequelize.query(UPDATE_CALIBRATION_STATUS, { transaction, type: QueryTypes.UPDATE });
await queryInterface.sequelize.query(ADD_CALIBRATION_STATUS_CONSTRAINT, { transaction, type: QueryTypes.RAW });
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(DELETE_CALIBRATION_STATUS_CONSTRAINT, { transaction });
await queryInterface.sequelize.query(DELETE_CALIBRATION_STATUS_CONSTRAINT, { transaction, type: QueryTypes.RAW });
await queryInterface.removeColumn('runs', 'calibration_status', { transaction });
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

'use strict';

const { QueryTypes } = require('sequelize');

const ROLLBACK_FILL_STATISTICS_TO_PREVIOUS = `
CREATE OR REPLACE VIEW fill_statistics AS
SELECT sbr.fill_number,
Expand Down Expand Up @@ -63,7 +65,7 @@ GROUP BY lf.fill_number;
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(UPDATE_FILL_STATISTICS_VIEW, { transaction });
await queryInterface.sequelize.query(UPDATE_FILL_STATISTICS_VIEW, { transaction, type: QueryTypes.RAW });
await queryInterface.addIndex(
'runs',
{
Expand All @@ -75,7 +77,7 @@ module.exports = {
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(ROLLBACK_FILL_STATISTICS_TO_PREVIOUS, { transaction });
await queryInterface.sequelize.query(ROLLBACK_FILL_STATISTICS_TO_PREVIOUS, { transaction, type: QueryTypes.RAW });
await queryInterface.removeIndex('runs', 'runs_fill_number_index', { transaction });
}),
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { QueryTypes } = require('sequelize');

const ADD_RUN_DURATION = `
ALTER TABLE runs
ADD COLUMN duration integer AS (TO_SECONDS(time_end) - TO_SECONDS(time_start)) VIRTUAL AFTER time_end;
Expand All @@ -8,7 +10,7 @@ const ADD_RUN_DURATION = `
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(ADD_RUN_DURATION, { transaction });
await queryInterface.sequelize.query(ADD_RUN_DURATION, { transaction, type: QueryTypes.RAW });
await queryInterface.addIndex('runs', {
name: 'runs_duration_idx',
fields: ['duration'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { QueryTypes } = require('sequelize');

const INSERT_PERIODS_QUERY = `
INSERT INTO lhc_periods(name)
SELECT DISTINCT lhc_period
Expand Down Expand Up @@ -57,8 +59,8 @@ module.exports = {
allowNull: true,
}, { transaction });

await queryInterface.sequelize.query(INSERT_PERIODS_QUERY);
await queryInterface.sequelize.query(UPDATE_RUNS_DATA_QUERY);
await queryInterface.sequelize.query(INSERT_PERIODS_QUERY, { type: QueryTypes.INSERT });
await queryInterface.sequelize.query(UPDATE_RUNS_DATA_QUERY, { type: QueryTypes.UPDATE });

await queryInterface.removeColumn('runs', 'lhc_period', { transaction });
}),
Expand All @@ -69,7 +71,7 @@ module.exports = {
allowNull: true,
}, { transaction });

await queryInterface.sequelize.query(UNDO_UPDATE_RUNS_DATA_QUERY);
await queryInterface.sequelize.query(UNDO_UPDATE_RUNS_DATA_QUERY, { type: QueryTypes.UPDATE });

await queryInterface.removeColumn('runs', 'lhc_period_id', { transaction });
await queryInterface.dropTable('lhc_periods', { transaction });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { QueryTypes } = require('sequelize');

// Incorrect values, fixed by migration 20241105125509-fix-physical-constants.js
const PARTICLES_PROPERTIES = { // 2 * sqrt(ATOMIC_MASS / ATOMIC_NUMBER)
['2#Z/A_pp']: 2 * Math.sqrt(1 / 1),
Expand Down Expand Up @@ -48,11 +50,11 @@ module.exports = {
.map(([key, value]) => ({ key, value })),
);

await queryInterface.sequelize.query(CREATE_PERIODS_VIEW, { transaction });
await queryInterface.sequelize.query(CREATE_PERIODS_VIEW, { transaction, type: QueryTypes.RAW });
}),

down: async (queryInterface, _) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(DROP_PERIODS_VIEW, { transaction });
await queryInterface.sequelize.query(DROP_PERIODS_VIEW, { transaction, type: QueryTypes.RAW });
await queryInterface.dropTable('physical_constants', { transaction });
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

'use strict';

const { QueryTypes } = require('sequelize');
const { RunDefinition } = require('../../../domain/enums/RunDefinition.js');

const REMOVE_DATA_PASSES_LINKS_TO_NON_PHYSICS_RUNS = `
Expand All @@ -32,11 +33,11 @@ const REMOVE_SIMULATION_PASSES_LINKS_TO_NON_PHYSICS_RUNS = `
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(REMOVE_DATA_PASSES_LINKS_TO_NON_PHYSICS_RUNS, { transaction });
await queryInterface.sequelize.query(REMOVE_SIMULATION_PASSES_LINKS_TO_NON_PHYSICS_RUNS, { transaction });
await queryInterface.sequelize.query(REMOVE_DATA_PASSES_LINKS_TO_NON_PHYSICS_RUNS, { transaction, type: QueryTypes.DELETE });
await queryInterface.sequelize.query(REMOVE_SIMULATION_PASSES_LINKS_TO_NON_PHYSICS_RUNS, { transaction, type: QueryTypes.DELETE });
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async () => {
await queryInterface.sequelize.query('SELECT \'THIS OPERTAION WAS IRREVERSIBLE\'');
await queryInterface.sequelize.query('SELECT \'THIS OPERTAION WAS IRREVERSIBLE\'', { type: QueryTypes.SELECT });
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

'use strict';

const { QueryTypes } = require('sequelize');

const UPDATE_FILL_STATISTICS_VIEW = `
CREATE OR REPLACE VIEW fill_statistics AS
SELECT lf.fill_number,
Expand Down Expand Up @@ -74,10 +76,10 @@ GROUP BY lf.fill_number;
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(UPDATE_FILL_STATISTICS_VIEW, { transaction });
await queryInterface.sequelize.query(UPDATE_FILL_STATISTICS_VIEW, { transaction, type: QueryTypes.RAW });
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(ROLLBACK_FILL_STATISTICS_TO_PREVIOUS, { transaction });
await queryInterface.sequelize.query(ROLLBACK_FILL_STATISTICS_TO_PREVIOUS, { transaction, type: QueryTypes.RAW });
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

const { timestampToMysql } = require('../../../server/utilities/timestampToMysql.js');
const { QueryTypes } = require('sequelize');

/**
* Remove time segments of effective periods of flags assigned to
Expand Down Expand Up @@ -69,7 +70,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async (
WHERE qcfep.\`from\` >= '${intersectingPeriodFrom}'
AND qcfep.\`to\` <= '${intersectingPeriodTo}'
`,
{ transaction },
{ transaction, type: QueryTypes.DELETE },
);

// Split effective periods which include new flag's period
Expand All @@ -81,7 +82,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async (
WHERE qcfep.\`from\` < '${intersectingPeriodFrom}'
AND '${intersectingPeriodTo}' < qcfep.\`to\`;

`, { transaction });
`, { transaction, type: QueryTypes.INSERT });
await queryInterface.sequelize.query(`
INSERT INTO quality_control_flag_effective_periods (\`from\`, \`to\`, flag_id)
SELECT '${intersectingPeriodTo}', qcfep.\`to\`, qcfep.flag_id
Expand All @@ -90,7 +91,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async (
WHERE qcfep.\`from\` < '${intersectingPeriodFrom}'
AND '${intersectingPeriodTo}' < qcfep.\`to\`;

`, { transaction });
`, { transaction, type: QueryTypes.INSERT });
await queryInterface.sequelize.query(
`
DELETE FROM qcfep
Expand All @@ -99,7 +100,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async (
WHERE qcfep.\`from\` < '${intersectingPeriodFrom}'
AND '${intersectingPeriodTo}' < qcfep.\`to\`;
`,
{ transaction },
{ transaction, type: QueryTypes.DELETE },
);

// Shrink effective periods that start before new flag's period
Expand All @@ -110,7 +111,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async (
WHERE qcfep.\`from\` < '${intersectingPeriodFrom}'
AND qcfep.\`to\` > '${intersectingPeriodFrom}'
;
`, { transaction });
`, { transaction, type: QueryTypes.UPDATE });

// Shrink effective periods that end after new flag's period
await queryInterface.sequelize.query(`
Expand All @@ -120,7 +121,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async (
WHERE qcfep.\`to\` > '${intersectingPeriodTo}'
AND qcfep.\`from\` < '${intersectingPeriodTo}'
;
`, { transaction });
`, { transaction, type: QueryTypes.UPDATE });
};

/**
Expand All @@ -131,7 +132,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async (
* @return {Promise<void>} resolve once all QC flags have proper effective periods assigned
*/
const _reconstructQcFlagsEffectivePeriods = async (queryInterface, { transaction }) => {
const [qcFlagsPerDataPass] = await queryInterface.sequelize.query(`
const qcFlagsPerDataPass = await queryInterface.sequelize.query(`
SELECT
\`from\`,
\`to\`,
Expand All @@ -144,7 +145,7 @@ const _reconstructQcFlagsEffectivePeriods = async (queryInterface, { transaction
ON qcf.id = dpqcf.quality_control_flag_id
ORDER by qcf.created_at ASC
;
`, { transaction });
`, { transaction, type: QueryTypes.SELECT });
for (const flag of qcFlagsPerDataPass) {
const {
from,
Expand All @@ -162,7 +163,7 @@ const _reconstructQcFlagsEffectivePeriods = async (queryInterface, { transaction
);
}

const [qcFlagsPerSimulationPass] = await queryInterface.sequelize.query(`
const qcFlagsPerSimulationPass = await queryInterface.sequelize.query(`
SELECT
\`from\`,
\`to\`,
Expand All @@ -175,7 +176,7 @@ const _reconstructQcFlagsEffectivePeriods = async (queryInterface, { transaction
ON qcf.id = spqcf.quality_control_flag_id
ORDER by qcf.created_at ASC
;
`, { transaction });
`, { transaction, type: QueryTypes.SELECT });

for (const flag of qcFlagsPerSimulationPass) {
const {
Expand Down Expand Up @@ -207,7 +208,7 @@ const _populateQcFlagEffectivePeriod = async (queryInterface, { transaction }) =
`
INSERT INTO quality_control_flag_effective_periods(flag_id, \`from\`, \`to\`)
SELECT qcf.id, qcf.\`from\`, qcf.\`to\` from quality_control_flags qcf;`,
{ transaction },
{ transaction, type: QueryTypes.INSERT },
);
};

Expand Down
Loading
Loading