diff --git a/lib/database/migrations/v0/20221010120629-convert-run-detectors-to-separate-table.js b/lib/database/migrations/v0/20221010120629-convert-run-detectors-to-separate-table.js index 85fe6d77a7..486d721366 100644 --- a/lib/database/migrations/v0/20221010120629-convert-run-detectors-to-separate-table.js +++ b/lib/database/migrations/v0/20221010120629-convert-run-detectors-to-separate-table.js @@ -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 }); } }); }, @@ -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 }); }, }; diff --git a/lib/database/migrations/v0/20221214064931-merge-flp-runs-in-flp-roles.js b/lib/database/migrations/v0/20221214064931-merge-flp-runs-in-flp-roles.js index d616060f60..dc45df0adc 100644 --- a/lib/database/migrations/v0/20221214064931-merge-flp-runs-in-flp-roles.js +++ b/lib/database/migrations/v0/20221214064931-merge-flp-runs-in-flp-roles.js @@ -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 }); }), @@ -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 }); diff --git a/lib/database/migrations/v0/20230120160345-add-environment-history.js b/lib/database/migrations/v0/20230120160345-add-environment-history.js index 492fec31ed..e5aced5916 100644 --- a/lib/database/migrations/v0/20230120160345-add-environment-history.js +++ b/lib/database/migrations/v0/20230120160345-add-environment-history.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + module.exports = { // eslint-disable-next-line jsdoc/require-jsdoc @@ -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'), @@ -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'); }); diff --git a/lib/database/migrations/v0/20230706083148-add-run-definition-column.js b/lib/database/migrations/v0/20230706083148-add-run-definition-column.js index 2424b4ab7d..0cabf28fdf 100644 --- a/lib/database/migrations/v0/20230706083148-add-run-definition-column.js +++ b/lib/database/migrations/v0/20230706083148-add-run-definition-column.js @@ -13,6 +13,8 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + const { RUN_DEFINITIONS } = require('../../../domain/enums/RunDefinition.js'); const SET_PHYSICS_DEFINITION = ` @@ -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, diff --git a/lib/database/migrations/v0/20230717163538-add-fill-statistics-view.js b/lib/database/migrations/v0/20230717163538-add-fill-statistics-view.js index 34bc3c924c..f5837118bd 100644 --- a/lib/database/migrations/v0/20230717163538-add-fill-statistics-view.js +++ b/lib/database/migrations/v0/20230717163538-add-fill-statistics-view.js @@ -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, @@ -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 }); }), diff --git a/lib/database/migrations/v0/20230821070256-add-run-calibration-status.js b/lib/database/migrations/v0/20230821070256-add-run-calibration-status.js index bbab32078c..3c2301e67c 100644 --- a/lib/database/migrations/v0/20230821070256-add-run-calibration-status.js +++ b/lib/database/migrations/v0/20230821070256-add-run-calibration-status.js @@ -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'); @@ -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 }); }), }; diff --git a/lib/database/migrations/v0/20230901090207-include-fill-without-runs-in-statistics.js b/lib/database/migrations/v0/20230901090207-include-fill-without-runs-in-statistics.js index fb4d537b5e..c3c116846a 100644 --- a/lib/database/migrations/v0/20230901090207-include-fill-without-runs-in-statistics.js +++ b/lib/database/migrations/v0/20230901090207-include-fill-without-runs-in-statistics.js @@ -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, @@ -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', { @@ -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 }); }), }; diff --git a/lib/database/migrations/v0/20230928091453-add-run-duration-column.js b/lib/database/migrations/v0/20230928091453-add-run-duration-column.js index 608d41eb59..997dfb538f 100644 --- a/lib/database/migrations/v0/20230928091453-add-run-duration-column.js +++ b/lib/database/migrations/v0/20230928091453-add-run-duration-column.js @@ -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; @@ -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'], diff --git a/lib/database/migrations/v0/20231011103554-create-lhc-period.js b/lib/database/migrations/v0/20231011103554-create-lhc-period.js index 15d3f740c9..639cae2205 100644 --- a/lib/database/migrations/v0/20231011103554-create-lhc-period.js +++ b/lib/database/migrations/v0/20231011103554-create-lhc-period.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + const INSERT_PERIODS_QUERY = ` INSERT INTO lhc_periods(name) SELECT DISTINCT lhc_period @@ -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 }); }), @@ -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 }); diff --git a/lib/database/migrations/v0/20231025101611-create-lhc-periods-view.js b/lib/database/migrations/v0/20231025101611-create-lhc-periods-view.js index c8c98bb472..368f9ba80d 100644 --- a/lib/database/migrations/v0/20231025101611-create-lhc-periods-view.js +++ b/lib/database/migrations/v0/20231025101611-create-lhc-periods-view.js @@ -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), @@ -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 }); }), }; diff --git a/lib/database/migrations/v0/20240216160730-remove-obsolate-non-physics-runs-links.js b/lib/database/migrations/v0/20240216160730-remove-obsolate-non-physics-runs-links.js index e47c6934ed..6ec10983f4 100644 --- a/lib/database/migrations/v0/20240216160730-remove-obsolate-non-physics-runs-links.js +++ b/lib/database/migrations/v0/20240216160730-remove-obsolate-non-physics-runs-links.js @@ -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 = ` @@ -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 }); }), }; diff --git a/lib/database/migrations/v0/20240423072839-add-sb-duration-to-fill-statistics-view.js b/lib/database/migrations/v0/20240423072839-add-sb-duration-to-fill-statistics-view.js index 9af48f74c5..0a1ff07426 100644 --- a/lib/database/migrations/v0/20240423072839-add-sb-duration-to-fill-statistics-view.js +++ b/lib/database/migrations/v0/20240423072839-add-sb-duration-to-fill-statistics-view.js @@ -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, @@ -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 }); }), }; diff --git a/lib/database/migrations/v0/20240424092020-add-qc-flag-effective-periods-table.js b/lib/database/migrations/v0/20240424092020-add-qc-flag-effective-periods-table.js index 0534c5a5f6..cecc3fe983 100644 --- a/lib/database/migrations/v0/20240424092020-add-qc-flag-effective-periods-table.js +++ b/lib/database/migrations/v0/20240424092020-add-qc-flag-effective-periods-table.js @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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(` @@ -120,7 +121,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async ( WHERE qcfep.\`to\` > '${intersectingPeriodTo}' AND qcfep.\`from\` < '${intersectingPeriodTo}' ; - `, { transaction }); + `, { transaction, type: QueryTypes.UPDATE }); }; /** @@ -131,7 +132,7 @@ const _updateEffectivePeriodForScopeAndPeriod = async ( * @return {Promise} 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\`, @@ -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, @@ -162,7 +163,7 @@ const _reconstructQcFlagsEffectivePeriods = async (queryInterface, { transaction ); } - const [qcFlagsPerSimulationPass] = await queryInterface.sequelize.query(` + const qcFlagsPerSimulationPass = await queryInterface.sequelize.query(` SELECT \`from\`, \`to\`, @@ -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 { @@ -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 }, ); }; diff --git a/lib/database/migrations/v0/20240430100347-delete-subsystems.js b/lib/database/migrations/v0/20240430100347-delete-subsystems.js index 1ab8483c46..9c1896d292 100644 --- a/lib/database/migrations/v0/20240430100347-delete-subsystems.js +++ b/lib/database/migrations/v0/20240430100347-delete-subsystems.js @@ -19,7 +19,7 @@ module.exports = { // Transition all logs with "subsystem" type to "comment" await queryInterface.sequelize.query( 'UPDATE logs SET subtype=\'comment\' WHERE subtype=\'subsystem\'', - { transaction, raw: true }, + { transaction, raw: true, type: QueryTypes.UPDATE }, ); await queryInterface.changeColumn('logs', 'subtype', { allowNull: false, diff --git a/lib/database/migrations/v0/20240606104339-extract-data-passes-versions-table.js b/lib/database/migrations/v0/20240606104339-extract-data-passes-versions-table.js index 850480791e..af273f6b95 100644 --- a/lib/database/migrations/v0/20240606104339-extract-data-passes-versions-table.js +++ b/lib/database/migrations/v0/20240606104339-extract-data-passes-versions-table.js @@ -13,7 +13,7 @@ 'use strict'; -const { Sequelize } = require('sequelize'); +const { QueryTypes, Sequelize } = require('sequelize'); /** @type {import('sequelize-cli').Migration} */ module.exports = { @@ -67,7 +67,7 @@ module.exports = { INSERT INTO data_pass_versions (data_pass_id, description, output_size, reconstructed_events_count) SELECT id, description, output_size, reconstructed_events_count FROM data_passes - `, { transaction }); + `, { transaction, type: QueryTypes.INSERT }); await queryInterface.removeColumn('data_passes', 'description', { transaction }); await queryInterface.removeColumn('data_passes', 'output_size', { transaction }); @@ -106,7 +106,7 @@ module.exports = { data_passes.output_size = recent_data_pass_version.output_size, data_passes.reconstructed_events_count = recent_data_pass_version.reconstructed_events_count - `, { transaction }); + `, { transaction, type: QueryTypes.UPDATE }); await queryInterface.dropTable('data_pass_versions', { transaction }); }), diff --git a/lib/database/migrations/v0/20240702074339-add-mc-reproducible-to-qc-flag-type.js b/lib/database/migrations/v0/20240702074339-add-mc-reproducible-to-qc-flag-type.js index 4afdd38afb..069edd1499 100644 --- a/lib/database/migrations/v0/20240702074339-add-mc-reproducible-to-qc-flag-type.js +++ b/lib/database/migrations/v0/20240702074339-add-mc-reproducible-to-qc-flag-type.js @@ -13,7 +13,7 @@ 'use strict'; -const { Sequelize } = require('sequelize'); +const { QueryTypes, Sequelize } = require('sequelize'); /** @type {import('sequelize-cli').Migration} */ module.exports = { @@ -27,7 +27,7 @@ module.exports = { UPDATE quality_control_flag_types SET monte_carlo_reproducible = true WHERE name = 'Limited Acceptance MC Reproducible' - `); + `, { type: QueryTypes.UPDATE }); }), down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { diff --git a/lib/database/migrations/v0/20240718120539-add-type-column-to-detectors.js b/lib/database/migrations/v0/20240718120539-add-type-column-to-detectors.js index 0a01581797..7c2c057c5c 100644 --- a/lib/database/migrations/v0/20240718120539-add-type-column-to-detectors.js +++ b/lib/database/migrations/v0/20240718120539-add-type-column-to-detectors.js @@ -13,7 +13,7 @@ 'use strict'; -const { Sequelize } = require('sequelize'); +const { QueryTypes, Sequelize } = require('sequelize'); const { DetectorType, DETECTOR_TYPES } = require('../../../domain/enums/DetectorTypes.js'); /** @type {import('sequelize-cli').Migration} */ @@ -49,13 +49,13 @@ module.exports = { await queryInterface.sequelize.query(` UPDATE detectors SET type = '${DetectorType.PHYSICAL}' - `, { transaction }); + `, { transaction, type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(` UPDATE detectors SET type = '${DetectorType.VIRTUAL}' WHERE name = 'TST' - `, { transaction }); + `, { transaction, type: QueryTypes.UPDATE }); }), down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { diff --git a/lib/database/migrations/v0/20240724134539-migrate-dpl-detectors-to-detectors.js b/lib/database/migrations/v0/20240724134539-migrate-dpl-detectors-to-detectors.js index 79f61d3b21..6a393440b2 100644 --- a/lib/database/migrations/v0/20240724134539-migrate-dpl-detectors-to-detectors.js +++ b/lib/database/migrations/v0/20240724134539-migrate-dpl-detectors-to-detectors.js @@ -13,7 +13,7 @@ 'use strict'; -const { Sequelize } = require('sequelize'); +const { QueryTypes, Sequelize } = require('sequelize'); const { DetectorType, DATA_TAKING_DETECTOR_TYPES } = require('../../../domain/enums/DetectorTypes.js'); /** @type {import('sequelize-cli').Migration} */ @@ -21,27 +21,27 @@ module.exports = { up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { await queryInterface.sequelize.query(` ALTER TABLE dpl_processes_executions RENAME COLUMN detector_id TO dpl_detector_id - `, { transaction }); + `, { transaction, type: QueryTypes.RAW }); await queryInterface.sequelize.query(` INSERT INTO detectors(id, name, type) SELECT id, name, '${DetectorType.QC_ONLY}' FROM dpl_detectors WHERE name != '' AND name NOT IN (SELECT name from detectors) - `, { transaction }); + `, { transaction, type: QueryTypes.INSERT }); await queryInterface.sequelize.query(` INSERT INTO detectors(id, name, type) SELECT id, name, '${DetectorType.OTHER}' FROM dpl_detectors WHERE name = '' AND name NOT IN (SELECT name from detectors) - `, { transaction }); + `, { transaction, type: QueryTypes.INSERT }); - const [constraints] = await queryInterface.sequelize.query(` + const constraints = await queryInterface.sequelize.query(` SELECT CONSTRAINT_NAME, UNIQUE_CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE REFERENCED_TABLE_NAME = 'dpl_detectors' - `, { transaction }); + `, { transaction, type: QueryTypes.SELECT }); for (const { CONSTRAINT_NAME, TABLE_NAME } of constraints) { await queryInterface.removeConstraint(TABLE_NAME, CONSTRAINT_NAME, { transaction }); @@ -53,7 +53,7 @@ module.exports = { INNER JOIN detectors AS d ON d.name = dpl.name SET u.dpl_detector_id = d.id - `); + `, { type: QueryTypes.UPDATE }); await queryInterface.addConstraint(TABLE_NAME, { type: 'FOREIGN KEY', @@ -64,7 +64,7 @@ module.exports = { field: 'id', }, }, { transaction }); - await queryInterface.sequelize.query(`ALTER TABLE ${TABLE_NAME} RENAME COLUMN dpl_detector_id TO detector_id`, { transaction }); + await queryInterface.sequelize.query(`ALTER TABLE ${TABLE_NAME} RENAME COLUMN dpl_detector_id TO detector_id`, { transaction, type: QueryTypes.RAW }); } await queryInterface.dropTable('dpl_detectors', { transaction }); @@ -98,14 +98,14 @@ module.exports = { INSERT INTO dpl_detectors(name) SELECT name FROM detectors - `, { transaction }); + `, { transaction, type: QueryTypes.INSERT }); - const [constraints] = await queryInterface.sequelize.query(` + const constraints = await queryInterface.sequelize.query(` SELECT CONSTRAINT_NAME, UNIQUE_CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE REFERENCED_TABLE_NAME = 'detectors' AND TABLE_NAME != 'run_detectors' - `, { transaction }); + `, { transaction, type: QueryTypes.SELECT }); for (const { CONSTRAINT_NAME, TABLE_NAME } of constraints) { await queryInterface.removeConstraint(TABLE_NAME, CONSTRAINT_NAME, { transaction }); @@ -116,7 +116,7 @@ module.exports = { INNER JOIN dpl_detectors AS dpl ON d.name = dpl.name SET u.detector_id = dpl.id - `); + `, { type: QueryTypes.UPDATE }); await queryInterface.addConstraint(TABLE_NAME, { type: 'FOREIGN KEY', @@ -128,16 +128,16 @@ module.exports = { }, }, { transaction }); - await queryInterface.sequelize.query(`ALTER TABLE ${TABLE_NAME} RENAME COLUMN detector_id TO dpl_detector_id`, { transaction }); + await queryInterface.sequelize.query(`ALTER TABLE ${TABLE_NAME} RENAME COLUMN detector_id TO dpl_detector_id`, { transaction, type: QueryTypes.RAW }); } await queryInterface.sequelize.query(` DELETE FROM detectors WHERE type NOT IN (${DATA_TAKING_DETECTOR_TYPES.map((type) => `'${type}'`)}) - `, { transaction }); + `, { transaction, type: QueryTypes.DELETE }); await queryInterface.sequelize.query(` ALTER TABLE dpl_processes_executions RENAME COLUMN dpl_detector_id TO detector_id - `, { transaction }); + `, { transaction, type: QueryTypes.RAW }); }), }; diff --git a/lib/database/migrations/v0/20240731134539-add-default-GAQ-detectors.js b/lib/database/migrations/v0/20240731134539-add-default-GAQ-detectors.js index 962af9834d..4bab7637f5 100644 --- a/lib/database/migrations/v0/20240731134539-add-default-GAQ-detectors.js +++ b/lib/database/migrations/v0/20240731134539-add-default-GAQ-detectors.js @@ -13,6 +13,8 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + const { DEFAULT_GAQ_DETECTORS_FOR_PROTON_PROTON_RUNS, DEFAULT_GAQ_DETECTORS_FOR_LEAD_LEAD_RUNS, @@ -41,7 +43,7 @@ module.exports = { INNER JOIN detectors AS d ON d.id = rd.detector_id AND d.name IN (:detectorsNames) - `, { transaction, replacements: { beamType, detectorsNames } }); + `, { transaction, replacements: { beamType, detectorsNames }, type: QueryTypes.INSERT }); await useDefaultGaqDetectorsForRunsWithGivenPdpBeamType('pp', DEFAULT_GAQ_DETECTORS_FOR_PROTON_PROTON_RUNS); await useDefaultGaqDetectorsForRunsWithGivenPdpBeamType('PbPb', DEFAULT_GAQ_DETECTORS_FOR_LEAD_LEAD_RUNS); diff --git a/lib/database/migrations/v0/20240801103339-add-data-passes-ML-status.js b/lib/database/migrations/v0/20240801103339-add-data-passes-ML-status.js index 87c6344b8a..728fa37d57 100644 --- a/lib/database/migrations/v0/20240801103339-add-data-passes-ML-status.js +++ b/lib/database/migrations/v0/20240801103339-add-data-passes-ML-status.js @@ -13,7 +13,7 @@ 'use strict'; -const { Sequelize } = require('sequelize'); +const { QueryTypes, Sequelize } = require('sequelize'); const { DATA_PASS_VERSION_STATUSES, DataPassVersionStatus } = require('../../../domain/enums/DataPassVersionStatus.js'); /** @type {import('sequelize-cli').Migration} */ @@ -57,13 +57,13 @@ module.exports = { INSERT INTO data_pass_version_status_history(data_pass_version_id, status, created_at, updated_at) SELECT id, :status, created_at, created_at FROM data_pass_versions - `, { transaction, replacements: { status: DataPassVersionStatus.RUNNING } }); + `, { transaction, replacements: { status: DataPassVersionStatus.RUNNING }, type: QueryTypes.INSERT }); await queryInterface.sequelize.query(` INSERT INTO data_pass_version_status_history(data_pass_version_id, status, created_at, updated_at) SELECT id, :status, updated_at, updated_at FROM data_pass_versions WHERE deleted_from_monalisa = true - `, { transaction, replacements: { status: DataPassVersionStatus.DELETED } }); + `, { transaction, replacements: { status: DataPassVersionStatus.DELETED }, type: QueryTypes.INSERT }); await queryInterface.removeColumn('data_pass_versions', 'deleted_from_monalisa', { transaction }); }), @@ -92,7 +92,7 @@ module.exports = { ON last_status.data_pass_version_id = dpv.id SET dpv.deleted_from_monalisa = true - `, { transaction, replacements: { statusDeleted: DataPassVersionStatus.DELETED } }); + `, { transaction, replacements: { statusDeleted: DataPassVersionStatus.DELETED }, type: QueryTypes.UPDATE }); await queryInterface.dropTable('data_pass_version_status_history', { transaction }); }), diff --git a/lib/database/migrations/v0/20240806160000-add-skimming-role-to-data-passes.js b/lib/database/migrations/v0/20240806160000-add-skimming-role-to-data-passes.js index 66ae0e97d1..596a5aa100 100644 --- a/lib/database/migrations/v0/20240806160000-add-skimming-role-to-data-passes.js +++ b/lib/database/migrations/v0/20240806160000-add-skimming-role-to-data-passes.js @@ -13,7 +13,7 @@ 'use strict'; -const { Sequelize } = require('sequelize'); +const { QueryTypes, Sequelize } = require('sequelize'); const { SKIMMING_STAGES, SkimmingStage } = require('../../../domain/enums/SkimmingStage.js'); /** @type {import('sequelize-cli').Migration} */ @@ -28,7 +28,7 @@ module.exports = { UPDATE data_passes SET skimming_stage = :skimmingStage WHERE name LIKE '%skimming%' - `, { transaction, replacements: { skimmingStage: SkimmingStage.SKIMMING } }); + `, { transaction, replacements: { skimmingStage: SkimmingStage.SKIMMING }, type: QueryTypes.UPDATE }); const numberedSkimmedPassesQuery = ` SELECT @@ -49,7 +49,7 @@ module.exports = { ON first_skimmed.id = dp.id SET dp.skimming_stage = :skimmingStage - `, { transaction, replacements: { skimmingStage: SkimmingStage.SKIMMED } }); + `, { transaction, replacements: { skimmingStage: SkimmingStage.SKIMMED }, type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(` UPDATE data_passes as dp @@ -62,7 +62,7 @@ module.exports = { ON later_skimmed.id = dp.id SET dp.skimming_stage = :skimmingStage - `, { transaction, replacements: { skimmingStage: SkimmingStage.POST_SKIMMED } }); + `, { transaction, replacements: { skimmingStage: SkimmingStage.POST_SKIMMED }, type: QueryTypes.UPDATE }); }), down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { diff --git a/lib/database/migrations/v1/20240904120543-store-environment-history-items-nanoseconds-timestamp.js b/lib/database/migrations/v1/20240904120543-store-environment-history-items-nanoseconds-timestamp.js index f34d144b55..e38fe92479 100644 --- a/lib/database/migrations/v1/20240904120543-store-environment-history-items-nanoseconds-timestamp.js +++ b/lib/database/migrations/v1/20240904120543-store-environment-history-items-nanoseconds-timestamp.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + /** @type {import('sequelize-cli').Migration} */ module.exports = { up: async (queryInterface, Sequelize) => queryInterface.sequelize.transaction(async (transaction) => { @@ -28,7 +30,7 @@ module.exports = { await queryInterface.sequelize.query( FILL_ENVIRONMENT_HISTORY_ITEMS_TIMESTAMPS, - { transaction }, + { transaction, type: QueryTypes.UPDATE }, ); }), diff --git a/lib/database/migrations/v1/20241105090940-store-run-and-qcflags-timestamps-in-ms.js b/lib/database/migrations/v1/20241105090940-store-run-and-qcflags-timestamps-in-ms.js index 0ce56a4364..e7674a54e9 100644 --- a/lib/database/migrations/v1/20241105090940-store-run-and-qcflags-timestamps-in-ms.js +++ b/lib/database/migrations/v1/20241105090940-store-run-and-qcflags-timestamps-in-ms.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + const TIME_START_END_TO_DATETIME_3 = ` ALTER TABLE runs CHANGE COLUMN time_start time_start DATETIME(3) AS (COALESCE(time_trg_start, time_trg_end)) VIRTUAL, @@ -136,7 +138,7 @@ module.exports = { { transaction }, ); - await queryInterface.sequelize.query(TIME_START_END_TO_DATETIME_3, { transaction }); + await queryInterface.sequelize.query(TIME_START_END_TO_DATETIME_3, { transaction, type: QueryTypes.RAW }); }), down: async (queryInterface, Sequelize) => queryInterface.sequelize.transaction(async (transaction) => { @@ -261,6 +263,6 @@ module.exports = { { transaction }, ); - await queryInterface.sequelize.query(TIME_START_END_TO_DATETIME, { transaction }); + await queryInterface.sequelize.query(TIME_START_END_TO_DATETIME, { transaction, type: QueryTypes.RAW }); }), }; diff --git a/lib/database/migrations/v1/20241105125509-fix-physical-constants.js b/lib/database/migrations/v1/20241105125509-fix-physical-constants.js index e313645f08..5b037b98b7 100644 --- a/lib/database/migrations/v1/20241105125509-fix-physical-constants.js +++ b/lib/database/migrations/v1/20241105125509-fix-physical-constants.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + // Fixes values set in 20231025101611-create-lhc-periods-view.js /** @type {import('sequelize-cli').Migration} */ @@ -8,32 +10,32 @@ module.exports = { await queryInterface.sequelize.query( // 2 * ATOMIC_NUMBER /ATOMIC_MASS => 2 * 82 / 207.2 'UPDATE physical_constants SET value=0.791505792 WHERE `key`=\'2#Z/A_PbPb\'', - { transaction }, + { transaction, type: QueryTypes.UPDATE }, ); await queryInterface.sequelize.query( // 2 * ATOMIC_NUMBER /ATOMIC_MASS => 2 * 8 / 15.999 'UPDATE physical_constants SET value=1.000062504 WHERE `key`=\'2#Z/A_OO\'', - { transaction }, + { transaction, type: QueryTypes.UPDATE }, ); await queryInterface.sequelize.query( // 2 * ATOMIC_NUMBER /ATOMIC_MASS => 2 * 54 / 131.293 'UPDATE physical_constants SET value=0.822587647 WHERE `key`=\'2#Z/A_XeXe\'', - { transaction }, + { transaction, type: QueryTypes.UPDATE }, ); }), down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { await queryInterface.sequelize.query( 'UPDATE physical_constants SET value=3.1792006972147466 WHERE `key`=\'2#Z/A_PbPb\'', - { transaction }, + { transaction, type: QueryTypes.UPDATE }, ); await queryInterface.sequelize.query( 'UPDATE physical_constants SET value=7.999974999960937 WHERE `key`=\'2#Z/A_OO\'', - { transaction }, + { transaction, type: QueryTypes.UPDATE }, ); await queryInterface.sequelize.query( 'UPDATE physical_constants SET value=22.916369695045503 WHERE `key`=\'2#Z/A_XeXe\'', - { transaction }, + { transaction, type: QueryTypes.UPDATE }, ); }), }; diff --git a/lib/database/migrations/v1/20241212074001-create-rct-run-start-and-stop.js b/lib/database/migrations/v1/20241212074001-create-rct-run-start-and-stop.js index 750400bae6..be73423f2f 100644 --- a/lib/database/migrations/v1/20241212074001-create-rct-run-start-and-stop.js +++ b/lib/database/migrations/v1/20241212074001-create-rct-run-start-and-stop.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + const ADD_RUN_RCT_START_AND_STOP = ` ALTER TABLE runs ADD COLUMN qc_time_start DATETIME(3) AS (COALESCE(first_tf_timestamp, time_trg_start, time_o2_start)) VIRTUAL AFTER time_start, @@ -8,7 +10,7 @@ const ADD_RUN_RCT_START_AND_STOP = ` /** @type {import('sequelize-cli').Migration} */ module.exports = { - up: async (queryInterface) => queryInterface.sequelize.query(ADD_RUN_RCT_START_AND_STOP), + up: async (queryInterface) => queryInterface.sequelize.query(ADD_RUN_RCT_START_AND_STOP, { type: QueryTypes.RAW }), down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { await queryInterface.removeColumn('runs', 'qc_time_start', { transaction }); diff --git a/lib/database/migrations/v1/20250211085415-rename-trigger-counters-to-ctp-trigger-counters.js b/lib/database/migrations/v1/20250211085415-rename-trigger-counters-to-ctp-trigger-counters.js index 37da4d0c6a..cf578e95fa 100644 --- a/lib/database/migrations/v1/20250211085415-rename-trigger-counters-to-ctp-trigger-counters.js +++ b/lib/database/migrations/v1/20250211085415-rename-trigger-counters-to-ctp-trigger-counters.js @@ -1,8 +1,10 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + /** @type {import('sequelize-cli').Migration} */ module.exports = { - up: async (queryInterface) => await queryInterface.sequelize.query('RENAME TABLE trigger_counters TO ctp_trigger_counters'), + up: async (queryInterface) => await queryInterface.sequelize.query('RENAME TABLE trigger_counters TO ctp_trigger_counters', { type: QueryTypes.RAW }), - down: async (queryInterface) => queryInterface.sequelize.query('RENAME TABLE ctp_trigger_counters TO trigger_counters'), + down: async (queryInterface) => queryInterface.sequelize.query('RENAME TABLE ctp_trigger_counters TO trigger_counters', { type: QueryTypes.RAW }), }; diff --git a/lib/database/migrations/v1/20250326133702-set-flag-bound-null-when-equal-to-run-end.js b/lib/database/migrations/v1/20250326133702-set-flag-bound-null-when-equal-to-run-end.js index 15e787ac0e..090d644c12 100644 --- a/lib/database/migrations/v1/20250326133702-set-flag-bound-null-when-equal-to-run-end.js +++ b/lib/database/migrations/v1/20250326133702-set-flag-bound-null-when-equal-to-run-end.js @@ -1,56 +1,58 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + /** @type {import('sequelize-cli').Migration} */ module.exports = { up: async (queryInterface) => queryInterface.sequelize.transaction(async () => { await queryInterface.sequelize.query(`UPDATE quality_control_flags qcf INNER JOIN runs r ON qcf.run_number = r.run_number SET qcf.\`from\` = NULL WHERE r.qc_time_start IS NOT NULL - AND qcf.\`from\` = r.qc_time_start`); + AND qcf.\`from\` = r.qc_time_start`, { type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(`UPDATE quality_control_flag_effective_periods qcfep INNER JOIN quality_control_flags qcf ON qcfep.flag_id = qcf.id INNER JOIN runs r ON qcf.run_number = r.run_number SET qcfep.\`from\` = NULL WHERE r.qc_time_start IS NOT NULL - AND qcfep.\`from\` = r.qc_time_start`); + AND qcfep.\`from\` = r.qc_time_start`, { type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(`UPDATE quality_control_flags qcf INNER JOIN runs r ON qcf.run_number = r.run_number SET qcf.\`to\` = NULL WHERE r.qc_time_end IS NOT NULL - AND qcf.\`to\` = r.qc_time_end`); + AND qcf.\`to\` = r.qc_time_end`, { type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(`UPDATE quality_control_flag_effective_periods qcfep INNER JOIN quality_control_flags qcf ON qcfep.flag_id = qcf.id INNER JOIN runs r ON qcf.run_number = r.run_number SET qcfep.\`to\` = NULL WHERE r.qc_time_end IS NOT NULL - AND qcfep.\`to\` = r.qc_time_end`); + AND qcfep.\`to\` = r.qc_time_end`, { type: QueryTypes.UPDATE }); }), down: async (queryInterface) => queryInterface.sequelize.transaction(async () => { await queryInterface.sequelize.query(`UPDATE quality_control_flags qcf INNER JOIN runs r ON qcf.run_number = r.run_number SET qcf.\`from\` = r.qc_time_start WHERE r.qc_time_start IS NOT NULL - AND qcf.\`from\` IS NULL`); + AND qcf.\`from\` IS NULL`, { type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(`UPDATE quality_control_flag_effective_periods qcfep INNER JOIN quality_control_flags qcf ON qcfep.flag_id = qcf.id INNER JOIN runs r ON qcf.run_number = r.run_number SET qcfep.\`from\` = r.qc_time_start WHERE r.qc_time_start IS NOT NULL - AND qcfep.\`from\` IS NULL`); + AND qcfep.\`from\` IS NULL`, { type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(`UPDATE quality_control_flags qcf INNER JOIN runs r ON qcf.run_number = r.run_number SET qcf.\`to\` = r.qc_time_end WHERE r.qc_time_end IS NOT NULL - AND qcf.\`to\` IS NULL`); + AND qcf.\`to\` IS NULL`, { type: QueryTypes.UPDATE }); await queryInterface.sequelize.query(`UPDATE quality_control_flag_effective_periods qcfep INNER JOIN quality_control_flags qcf ON qcfep.flag_id = qcf.id INNER JOIN runs r ON qcf.run_number = r.run_number SET qcfep.\`to\` = r.qc_time_end WHERE r.qc_time_end IS NOT NULL - AND qcfep.\`to\` IS NULL`); + AND qcfep.\`to\` IS NULL`, { type: QueryTypes.UPDATE }); }), }; diff --git a/lib/database/migrations/v1/20250328151300-add-qc-flag-boundaries-update-trigger.js b/lib/database/migrations/v1/20250328151300-add-qc-flag-boundaries-update-trigger.js index f94ed040a1..0dbf4d4b72 100644 --- a/lib/database/migrations/v1/20250328151300-add-qc-flag-boundaries-update-trigger.js +++ b/lib/database/migrations/v1/20250328151300-add-qc-flag-boundaries-update-trigger.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + const CREATE_QCF_BOUNDARIES_TRIGGER = ` CREATE TRIGGER qcf_boundaries_update_on_run_timestamps_update AFTER UPDATE ON runs @@ -72,8 +74,8 @@ const DROP_QCF_BOUNDARIES_TRIGGER = ` /** @type {import('sequelize-cli').Migration} */ module.exports = { up: async (queryInterface) => queryInterface.sequelize.transaction(() => - queryInterface.sequelize.query(CREATE_QCF_BOUNDARIES_TRIGGER)), + queryInterface.sequelize.query(CREATE_QCF_BOUNDARIES_TRIGGER, { type: QueryTypes.RAW })), down: async (queryInterface) => queryInterface.sequelize.transaction(() => - queryInterface.sequelize.query(DROP_QCF_BOUNDARIES_TRIGGER)), + queryInterface.sequelize.query(DROP_QCF_BOUNDARIES_TRIGGER, { type: QueryTypes.RAW })), }; diff --git a/lib/database/migrations/v1/20250518123000-create-gaq-views.js b/lib/database/migrations/v1/20250518123000-create-gaq-views.js index 65e4bb3532..4781404ed9 100644 --- a/lib/database/migrations/v1/20250518123000-create-gaq-views.js +++ b/lib/database/migrations/v1/20250518123000-create-gaq-views.js @@ -1,5 +1,7 @@ 'use strict'; +const { QueryTypes } = require('sequelize'); + const SELECT_RUNS_START_TIMESTAMPS_FOR_GAQ_PERIODS = ` SELECT gaqd.data_pass_id, @@ -155,14 +157,14 @@ const DROP_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION = 'DROP FUNCTIO /** @type {import('sequelize-cli').Migration} */ module.exports = { up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { - await queryInterface.sequelize.query(CREATE_GAQ_PERIODS_VIEW, { transaction }); - await queryInterface.sequelize.query(CREATE_QC_FLAG_BLOCK_SIGNIFCANCE_AGGREGATE_FUNCTION, { transaction }); - await queryInterface.sequelize.query(CREATE_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION, { transaction }); + await queryInterface.sequelize.query(CREATE_GAQ_PERIODS_VIEW, { transaction, type: QueryTypes.RAW }); + await queryInterface.sequelize.query(CREATE_QC_FLAG_BLOCK_SIGNIFCANCE_AGGREGATE_FUNCTION, { transaction, type: QueryTypes.RAW }); + await queryInterface.sequelize.query(CREATE_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION, { transaction, type: QueryTypes.RAW }); }), down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { - await queryInterface.sequelize.query(DROP_GAQ_PERIODS_VIEW, { transaction }); - await queryInterface.sequelize.query(DROP_QC_FLAG_BLOCK_SIGNIFCANCE_AGGREGATE_FUNCTION, { transaction }); - await queryInterface.sequelize.query(DROP_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION, { transaction }); + await queryInterface.sequelize.query(DROP_GAQ_PERIODS_VIEW, { transaction, type: QueryTypes.RAW }); + await queryInterface.sequelize.query(DROP_QC_FLAG_BLOCK_SIGNIFCANCE_AGGREGATE_FUNCTION, { transaction, type: QueryTypes.RAW }); + await queryInterface.sequelize.query(DROP_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION, { transaction, type: QueryTypes.RAW }); }), }; diff --git a/lib/database/repositories/EnvironmentHistoryItemRepository.js b/lib/database/repositories/EnvironmentHistoryItemRepository.js index ca0b4910d2..e1d553e6ca 100644 --- a/lib/database/repositories/EnvironmentHistoryItemRepository.js +++ b/lib/database/repositories/EnvironmentHistoryItemRepository.js @@ -12,6 +12,7 @@ */ const { models: { EnvironmentHistoryItem }, sequelize } = require('../'); +const { QueryTypes } = require('sequelize'); const Repository = require('./Repository'); const { timestampToMysql } = require('../../server/utilities/timestampToMysql.js'); @@ -66,7 +67,7 @@ class EnvironmentHistoryItemRepository extends Repository { * @return {Promise<{statusHistory: string, count: number}[]>} the resulting histogram */ async getHistoryDistribution(period) { - const [rows] = await sequelize.query(getHistoryDistributionQuery(period), { raw: true }); + const rows = await sequelize.query(getHistoryDistributionQuery(period), { raw: true, type: QueryTypes.SELECT }); return rows; } } diff --git a/lib/database/repositories/LogRepository.js b/lib/database/repositories/LogRepository.js index 58e7cfd6d4..729be1c7ae 100644 --- a/lib/database/repositories/LogRepository.js +++ b/lib/database/repositories/LogRepository.js @@ -12,6 +12,7 @@ */ const { models: { Log }, sequelize, utilities: { QueryBuilder } } = require('../'); +const { QueryTypes } = require('sequelize'); const Repository = require('./Repository'); const { timestampToMysql } = require('../../server/utilities/timestampToMysql.js'); @@ -33,6 +34,7 @@ const getTagDistributionQuery = ({ from, to }) => sequelize.query(` ORDER BY COUNT(*) DESC, t.text `, { replacements: { fromTimeStamp: timestampToMysql(from), toTimeStamp: timestampToMysql(to) }, + type: QueryTypes.SELECT, }); /** @@ -53,6 +55,7 @@ const getLogsWithReplyCountQuery = (logIds) => sequelize.query(` SELECT originLogId, COUNT(*) - 1 as replyCount FROM log_tree GROUP BY originLogId; `, { replacements: { logIds }, + type: QueryTypes.SELECT, }); /** @@ -79,7 +82,7 @@ class LogRepository extends Repository { return rows; } - const [results] = await getLogsWithReplyCountQuery(logIds); + const results = await getLogsWithReplyCountQuery(logIds); results.forEach((result) => { const count = result.replyCount || 0; @@ -117,8 +120,7 @@ class LogRepository extends Repository { * @return {Promise<{tag: string, count: number}[]>} the tag and their amount */ async getTagDistribution(period) { - const [rows] = await getTagDistributionQuery(period); - return rows; + return getTagDistributionQuery(period); } } diff --git a/lib/database/repositories/QcFlagRepository.js b/lib/database/repositories/QcFlagRepository.js index ca07d1660a..7a0d628a56 100644 --- a/lib/database/repositories/QcFlagRepository.js +++ b/lib/database/repositories/QcFlagRepository.js @@ -11,7 +11,7 @@ * or submit itself to any jurisdiction. */ -const { Op } = require('sequelize'); +const { Op, QueryTypes } = require('sequelize'); const { models: { QcFlag } } = require('..'); const Repository = require('./Repository'); @@ -84,7 +84,7 @@ class QcFlagRepository extends Repository { gaq_periods.\`to\`; `; - const [rows] = await this.model.sequelize.query(query); + const rows = await this.model.sequelize.query(query, { type: QueryTypes.SELECT }); return rows.map(({ dataPassId, runNumber, @@ -172,7 +172,7 @@ class QcFlagRepository extends Repository { replacements.runNumber = runNumber; } - const [rows] = await this.model.sequelize.query(summaryQuery, { replacements }); + const rows = await this.model.sequelize.query(summaryQuery, { replacements, type: QueryTypes.SELECT }); const entries = rows.map(({ run_number, bad_coverage, diff --git a/lib/database/repositories/StableBeamRunsRepository.js b/lib/database/repositories/StableBeamRunsRepository.js index 95905ee4fa..7b58b0653e 100644 --- a/lib/database/repositories/StableBeamRunsRepository.js +++ b/lib/database/repositories/StableBeamRunsRepository.js @@ -13,7 +13,7 @@ const { models: { StableBeamRun }, sequelize } = require('../'); const Repository = require('./Repository.js'); -const { Op } = require('sequelize'); +const { Op, QueryTypes } = require('sequelize'); const { RunQualities } = require('../../domain/enums/RunQualities.js'); const { timestampToMysql } = require('../../server/utilities/timestampToMysql.js'); const { RunDefinition } = require('../../domain/enums/RunDefinition.js'); @@ -138,7 +138,10 @@ class StableBeamRunsRepository extends Repository { * @return {Promise} the resulting histogram bins */ async getTimeBetweenRunsDistribution(period, timeWindow, restWindow) { - const [rows] = await sequelize.query(getTimeBetweenRunsHistogramQuery(period, timeWindow, restWindow), { raw: true }); + const rows = await sequelize.query( + getTimeBetweenRunsHistogramQuery(period, timeWindow, restWindow), + { raw: true, type: QueryTypes.SELECT }, + ); return rows; } @@ -149,7 +152,7 @@ class StableBeamRunsRepository extends Repository { * @return {Promise<{fillNumber: number, detectorName: string, efficiency: string, netEfficiency: string}[]>} the efficiency statistics */ async getEfficienciesPerFillPerDetector(period) { - const [rows] = await sequelize.query(getEfficiencyPerDetectorsQuery(period), { raw: true }); + const rows = await sequelize.query(getEfficiencyPerDetectorsQuery(period), { raw: true, type: QueryTypes.SELECT }); return rows; } @@ -160,7 +163,7 @@ class StableBeamRunsRepository extends Repository { * @return {Promise<{category: string, title: number, count: number}[]>} the resulting histogram */ async getEorDistribution(period) { - const [rows] = await sequelize.query(getEorDistributionQuery(period), { raw: true }); + const rows = await sequelize.query(getEorDistributionQuery(period), { raw: true, type: QueryTypes.SELECT }); return rows; } } diff --git a/lib/server/services/environment/getEnvironmentsInPeriod.js b/lib/server/services/environment/getEnvironmentsInPeriod.js index 973ac28858..e7caf9ef11 100644 --- a/lib/server/services/environment/getEnvironmentsInPeriod.js +++ b/lib/server/services/environment/getEnvironmentsInPeriod.js @@ -12,7 +12,7 @@ */ const { sequelize } = require('../../../database'); -const { Op } = require('sequelize'); +const { Op, QueryTypes } = require('sequelize'); const { EnvironmentRepository } = require('../../../database/repositories/index.js'); const { environmentIncludeClauseFromRelations } = require('./environmentIncludeClauseFromRelations.js'); const { timestampToMysql } = require('../../utilities/timestampToMysql.js'); @@ -39,7 +39,7 @@ exports.getEnvironmentsInPeriod = async ({ from, to }, relations) => { const lostIfNoNewsSince = from - ENVIRONMENT_CONSIDERED_LOST_AFTER; // Fetch the ids of the environments with a raw query because the needs are complex - const [rows] = await sequelize.query(` + const rows = await sequelize.query(` SELECT e.id FROM environments_history_items ehi INNER JOIN environments e on ehi.environment_id = e.id @@ -50,7 +50,7 @@ exports.getEnvironmentsInPeriod = async ({ from, to }, relations) => { AND GROUP_CONCAT(ehi.status) NOT LIKE '%ERROR%' AND GROUP_CONCAT(ehi.status) NOT LIKE '%DESTROYED%' AND GROUP_CONCAT(ehi.status) NOT LIKE '%DONE%' - `); + `, { type: QueryTypes.SELECT }); const ids = rows.map(({ id }) => id); return EnvironmentRepository.findAll({ diff --git a/lib/server/services/environment/transitionToErrorLostEnvironments.js b/lib/server/services/environment/transitionToErrorLostEnvironments.js index 109abf178a..8ef43976e4 100644 --- a/lib/server/services/environment/transitionToErrorLostEnvironments.js +++ b/lib/server/services/environment/transitionToErrorLostEnvironments.js @@ -13,6 +13,7 @@ const { sequelize } = require('../../../database/index.js'); const { utilities: { TransactionHelper } } = require('../../../database'); +const { QueryTypes } = require('sequelize'); const { EnvironmentHistoryItemRepository } = require('../../../database/repositories/index.js'); const { timestampToMysql } = require('../../utilities/timestampToMysql.js'); @@ -41,7 +42,7 @@ exports.transitionToErrorLostEnvironments = async (activeEnvironmentIds, modific } return TransactionHelper.provide(async () => { - const [rows] = await sequelize.query(selectQuery, { raw: true }); + const rows = await sequelize.query(selectQuery, { raw: true, type: QueryTypes.SELECT }); const ret = []; /** diff --git a/lib/server/services/run/setO2StopOfLostRuns.js b/lib/server/services/run/setO2StopOfLostRuns.js index 282ee166db..01cef5ef04 100644 --- a/lib/server/services/run/setO2StopOfLostRuns.js +++ b/lib/server/services/run/setO2StopOfLostRuns.js @@ -12,6 +12,7 @@ */ const { sequelize } = require('../../../database/index.js'); +const { QueryTypes } = require('sequelize'); const { timestampToMysql } = require('../../utilities/timestampToMysql.js'); /** @@ -36,7 +37,7 @@ exports.setO2StopOfLostRuns = async (runNumbersOfRunningRuns, modificationTimePe fetchQuery += ` AND run_number NOT IN (${runNumbersOfRunningRuns.join(',')})`; } - const [runs] = await sequelize.query(fetchQuery, { raw: true }); + const runs = await sequelize.query(fetchQuery, { raw: true, type: QueryTypes.SELECT }); const runNumbers = runs.map(({ run_number }) => run_number); if (runNumbers.length > 0) { @@ -44,7 +45,7 @@ exports.setO2StopOfLostRuns = async (runNumbersOfRunningRuns, modificationTimePe UPDATE runs SET time_o2_end = now() WHERE run_number IN (${runNumbers.join(',')}) - `); + `, { type: QueryTypes.UPDATE }); } return runNumbers; diff --git a/package-lock.json b/package-lock.json index 653853eba3..40381e2e1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "dotenv": "17.4.2", "joi": "18.2.5", "kafkajs": "2.2.4", - "mariadb": "3.0.0", + "mariadb": "3.2.5", "multer": "2.3.0", "node-fetch": "3.3.2", "sequelize": "6.37.8", @@ -91,18 +91,6 @@ "node": ">= 22.x" } }, - "node_modules/@alloc/quick-lru": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz", - "integrity": "sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw==", - "inBundle": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/@babel/code-frame": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", @@ -1955,10 +1943,11 @@ "license": "MIT" }, "node_modules/@types/geojson": { - "version": "7946.0.8", - "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.8.tgz", - "integrity": "sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==", - "inBundle": true + "version": "7946.0.16", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.16.tgz", + "integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==", + "inBundle": true, + "license": "MIT" }, "node_modules/@types/json-schema": { "version": "7.0.15", @@ -1974,10 +1963,11 @@ "inBundle": true }, "node_modules/@types/node": { - "version": "17.0.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", - "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==", - "inBundle": true + "version": "17.0.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", + "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==", + "inBundle": true, + "license": "MIT" }, "node_modules/@types/triple-beam": { "version": "1.3.5", @@ -3423,10 +3413,11 @@ } }, "node_modules/denque": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz", - "integrity": "sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", "inBundle": true, + "license": "Apache-2.0", "engines": { "node": ">=0.10" } @@ -5870,18 +5861,17 @@ } }, "node_modules/mariadb": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.0.0.tgz", - "integrity": "sha512-1uIqD6AWLP5ojMY67XP4+4uRLe9L92HD1ZGU8fidi8cGdYIC+Ghx1JliAtf7lc/tGjOh6J400f/1M4BXVtZFvA==", + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.2.5.tgz", + "integrity": "sha512-lo6ML7oyBatQwZ/pIKwwYEVy3BhA2jlL6Xurt6SIT8xKi2qYRY9sER3XRIqbHuYo7rgrSrYoQ/bet/uFu3+2jQ==", "inBundle": true, + "license": "LGPL-2.1-or-later", "dependencies": { - "@alloc/quick-lru": "^5.2.0", - "@types/geojson": "^7946.0.8", - "@types/node": "^17.0.10", - "denque": "^2.0.1", + "@types/geojson": "^7946.0.10", + "@types/node": "^17.0.45", + "denque": "^2.1.0", "iconv-lite": "^0.6.3", - "moment-timezone": "^0.5.34", - "please-upgrade-node": "^3.2.0" + "lru-cache": "^10.0.1" }, "engines": { "node": ">= 12" @@ -5899,6 +5889,13 @@ "node": ">=0.10.0" } }, + "node_modules/mariadb/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "inBundle": true, + "license": "ISC" + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -7172,15 +7169,6 @@ "node": ">=8" } }, - "node_modules/please-upgrade-node": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz", - "integrity": "sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==", - "inBundle": true, - "dependencies": { - "semver-compare": "^1.0.0" - } - }, "node_modules/pony-cause": { "version": "2.1.10", "resolved": "https://registry.npmjs.org/pony-cause/-/pony-cause-2.1.10.tgz", @@ -7672,12 +7660,6 @@ "semver": "bin/semver" } }, - "node_modules/semver-compare": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", - "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=", - "inBundle": true - }, "node_modules/send": { "version": "0.19.2", "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", diff --git a/package.json b/package.json index 1c38cb7c1d..7fb3d753b4 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dotenv": "17.4.2", "joi": "18.2.5", "kafkajs": "2.2.4", - "mariadb": "3.0.0", + "mariadb": "3.2.5", "multer": "2.3.0", "node-fetch": "3.3.2", "sequelize": "6.37.8",