Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
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
9 changes: 9 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

const path = require('path');

module.exports = {
'config': path.resolve('app', 'config', 'database.js'),
'models-path': path.resolve('app', 'lib', 'database', 'models'),
'seeders-path': path.resolve('app', 'lib', 'database', 'seeders'),
'migrations-path': path.resolve('app', 'lib', 'database', 'migrations')
};
28 changes: 28 additions & 0 deletions app/config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
const { ResProvider } = require('../lib/utils');

const legacyConfig = ResProvider.database();

const config = { ...legacyConfig,
username: legacyConfig.user, // TEMPORARILY
logging: legacyConfig.logging ? this.logger.debug.bind(this.logger) : false,
dialect: 'postgres',
define: {
underscored: true,
schema: this.schema,
},
};

module.exports = config;
2 changes: 1 addition & 1 deletion app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = Object.freeze({

// App config
winston: ResProvider.winston(),
database: ResProvider.database(),
database: require('./database.js'),
syncTaskAtStart: ResProvider.envOrDef('RCT_SYNC_TASK_AT_START', false, Boolean),
rctData: require('./rct-data'),
public: require('./public.js'),
Expand Down
8 changes: 4 additions & 4 deletions app/config/rct-data/healthcheckQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const checkStaticData = {
},
particle: {
description: 'Particles dict insert',
query: Object.entries(physicalParticlesData).map(([name, d]) => `INSERT INTO particle_phys_data("id", "name", "full_name", "A", "Z")
query: Object.entries(physicalParticlesData).map(([name, d]) => `INSERT INTO particle_phys_data("id", "name", "full_name", "a", "z")
VALUES (DEFAULT, '${name}', '${d.full_name}', ${d.A}, ${d.Z});`),
},
flags: {
Expand All @@ -39,9 +39,9 @@ const metaObj = {
},
};

const queryForName = (name) => `SELECT name, val, extract(epoch from "updatedAt") as "udatedAt" FROM meta WHERE name = '${name}'`;
const updateForName = (name, val) => `INSERT INTO meta (name, val, "updatedAt") values ('${name}', '${val}', now())
ON conflict (name) do update set val = EXCLUDED.val, "updatedAt" = now();`;
const queryForName = (name) => `SELECT name, val, extract(epoch from "updated_at") as "udatedAt" FROM meta WHERE name = '${name}'`;
const updateForName = (name, val) => `INSERT INTO meta (name, val, "updated_at") values ('${name}', '${val}', now())
ON conflict (name) do update set val = EXCLUDED.val, "updated_at" = now();`;

const meta = {
objects: metaObj,
Expand Down
3 changes: 0 additions & 3 deletions app/lib/alimonitor-services/MonalisaService.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ class MonalisaService extends AbstractServiceSynchronizer {
${d.name},
${d.period.name},
${d.description},
${null},
${null},
${d.number_of_events},
${null},
${d.size},
${d.last_run}
);`;
Expand Down
15 changes: 5 additions & 10 deletions app/lib/alimonitor-services/MonalisaServiceMC.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class MonalisaServiceMC extends AbstractServiceSynchronizer {
EndpointsFormatter.mcRaw(),
this.responsePreprocess.bind(this),
this.dataAdjuster.bind(this),
(r) => {
const { anchor_productions, anchor_passes } = r;
return r.period.year >= config.dataFromYearIncluding && anchor_productions.length != 0 && anchor_passes.length != 0;
// MC not anchored to any production so drop out
(simulation_pass) => {
const { anchor_productions, anchor_passes } = simulation_pass;
return simulation_pass.period.year >= config.dataFromYearIncluding
&& anchor_productions.length != 0 && anchor_passes.length != 0;
// MC not anchored to any production or pass so drop out
},
this.dbAction.bind(this),
);
Expand Down Expand Up @@ -88,11 +89,6 @@ class MonalisaServiceMC extends AbstractServiceSynchronizer {
}

async dbAction(dbClient, d) {
const { anchor_productions, anchor_passes } = d;
if (anchor_productions.length == 0 || anchor_passes.length == 0) {
// MC not anchored to any production so drop out
return;
}
d = Utils.adjusetObjValuesToSql(d);
const { period } = d;
const period_insert =
Expand All @@ -108,7 +104,6 @@ class MonalisaServiceMC extends AbstractServiceSynchronizer {
${anchord_prod_sql},
${anchord_passes_sql},
${d.jira},
${null},
${d.number_of_events},
${d.size}
); call insert_mc_details(${d.name}, ${d.runs}::integer[], ${period.name});`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('beams_dictionary', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
beam_type: {
type: Sequelize.STRING,
unique: true,
},
},
)
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('beams_dictionary');
}
};
45 changes: 45 additions & 0 deletions app/lib/database/migrations/20230816140200-create-periods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('periods', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
unique: true,
},
year: {
type: Sequelize.INTEGER,
},
beam_type_id: {
type: Sequelize.INTEGER,
allowNull: true,
references: {
model: 'beams_dictionary',
key: 'id',
},
},
},
)
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('periods');
}
};
63 changes: 63 additions & 0 deletions app/lib/database/migrations/20230816140300-create-runs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('runs', {
run_number: {
type: Sequelize.INTEGER,
primaryKey: true,
},
time_start: {
type: Sequelize.BIGINT,
},
time_end: {
type: Sequelize.BIGINT,
},
time_trg_start: {
type: Sequelize.BIGINT,
},
time_trg_end: {
type: Sequelize.BIGINT,
},
energy_per_beam: {
type: Sequelize.FLOAT,
},
l3_current: {
type: Sequelize.FLOAT,
},
dipole_current: {
type: Sequelize.FLOAT,
},
fill_number: {
type: Sequelize.INTEGER,
},
run_type: {
type: Sequelize.STRING,
},
period_id: {
type: Sequelize.INTEGER,
allowNull: true,
references: {
model: 'periods',
key: 'id',
},
},
},
)
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('runs');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('detectors_subsystems', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
unique: true,
},
},
)
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('detectors_subsystems');
}
};
54 changes: 54 additions & 0 deletions app/lib/database/migrations/20230816140500-create-data_passes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('data_passes', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
unique: true,
},
description: {
type: Sequelize.TEXT,
},
number_of_events: {
type: Sequelize.INTEGER,
},
size: {
type: Sequelize.REAL,
},
last_run: {
type: Sequelize.INTEGER,
},
period_id: {
type: Sequelize.INTEGER,
allowNull: true,
references: {
model: 'periods',
key: 'id',
},
},
},
)
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('data_passes');
}
};
Loading