Skip to content
Open
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
51 changes: 51 additions & 0 deletions lib/database/adapters/TemplateAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @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.
*/
/**
* Adapter for templates
*/
class TemplateAdapter {
/**
* Constructor
*/
constructor() {
this.toEntity = this.toEntity.bind(this);

/**
* @type {TemplateModuleAdapter|null}
*/
this.templateModuleAdapter = null;
}

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeTemplate} databaseObject Object to convert.
* @returns {Template} Converted entity object.
*/
toEntity({ id, name, title, description, modules }) {
const entityObject = {
id,
name,
title,
description,
};

if (modules) {
entityObject.modules = modules.map(this.templateModuleAdapter.toEntity);
}

return entityObject;
}
}

module.exports = TemplateAdapter;
40 changes: 40 additions & 0 deletions lib/database/adapters/TemplateModuleAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @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.
*/
/**
* Adapter for template modules
*/
class TemplateModuleAdapter {
/**
* Constructor
*/
constructor() {
this.toEntity = this.toEntity.bind(this);
}

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeTemplateModule} databaseObject Object to convert.
* @returns {TemplateModule} Converted entity object.
*/
toEntity({ position, type, title, options }) {
return {
position,
type,
title,
options,
};
}
}

module.exports = TemplateModuleAdapter;
7 changes: 7 additions & 0 deletions lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const RunTypeAdapter = require('./RunTypeAdapter');
const SimulationPassAdapter = require('./SimulationPassAdapter.js');
const { SimulationPassQcFlagAdapter } = require('./SimulationPassQcFlagAdapter');
const TagAdapter = require('./TagAdapter');
const TemplateAdapter = require('./TemplateAdapter.js');
const TemplateModuleAdapter = require('./TemplateModuleAdapter.js');
const { CtpTriggerCountersAdapter } = require('./CtpTriggerCountersAdapter');
const UserAdapter = require('./UserAdapter');

Expand Down Expand Up @@ -82,6 +84,8 @@ const runTypeAdapter = new RunTypeAdapter();
const simulationPassAdapter = new SimulationPassAdapter();
const simulationPassQcFlagAdapter = new SimulationPassQcFlagAdapter();
const tagAdapter = new TagAdapter();
const templateAdapter = new TemplateAdapter();
const templateModuleAdapter = new TemplateModuleAdapter();
const ctpTriggerCountersAdapter = new CtpTriggerCountersAdapter();
const userAdapter = new UserAdapter();

Expand Down Expand Up @@ -144,6 +148,7 @@ runAdapter.tagAdapter = tagAdapter;
runAdapter.userAdapter = userAdapter;

tagAdapter.userAdapter = userAdapter;
templateAdapter.templateModuleAdapter = templateModuleAdapter;
runAdapter.qcFlagAdapter = qcFlagAdapter;

simulationPassQcFlagAdapter.simulationPassAdapter = simulationPassAdapter;
Expand Down Expand Up @@ -183,6 +188,8 @@ module.exports = {
simulationPassAdapter,
simulationPassQcFlagAdapter,
tagAdapter,
templateAdapter,
templateModuleAdapter,
ctpTriggerCountersAdapter,
userAdapter,
};
105 changes: 105 additions & 0 deletions lib/database/migrations/v1/20261028100000-create-templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @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.
*/

'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.createTable('templates', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
name: {
allowNull: false,
unique: true,
type: Sequelize.STRING(64),
},
title: {
allowNull: false,
type: Sequelize.STRING(255),
},
description: {
allowNull: true,
type: Sequelize.TEXT,
},
created_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
},
}, { transaction });

await queryInterface.createTable('template_modules', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
template_id: {
allowNull: false,
type: Sequelize.INTEGER,
references: { model: 'templates', key: 'id' },
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
position: {
allowNull: false,
type: Sequelize.INTEGER,
},
type: {
allowNull: false,
type: Sequelize.STRING(64),
},
title: {
allowNull: true,
type: Sequelize.STRING(255),
},
options: {
allowNull: false,
type: Sequelize.JSON,
},
created_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
},
}, { transaction });

await queryInterface.addConstraint('template_modules', {
fields: ['template_id', 'position'],
type: 'unique',
name: 'template_modules_template_id_position',
transaction,
});
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.dropTable('template_modules', { transaction });
await queryInterface.dropTable('templates', { transaction });
}),
};
4 changes: 4 additions & 0 deletions lib/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const SimulationPass = require('./simulationPass.js');
const SimulationPassQcFlag = require('./simulationPassQcFlag.js');
const StableBeamRun = require('./stableBeamsRun.js');
const Tag = require('./tag');
const Template = require('./template.js');
const TemplateModule = require('./templateModule.js');
const CtpTriggerCounters = require('./ctpTriggerCounters');
const User = require('./user');

Expand Down Expand Up @@ -84,6 +86,8 @@ module.exports = (sequelize) => {
SimulationPassQcFlag: SimulationPassQcFlag(sequelize),
StableBeamRun: StableBeamRun(sequelize),
Tag: Tag(sequelize),
Template: Template(sequelize),
TemplateModule: TemplateModule(sequelize),
CtpTriggerCounters: CtpTriggerCounters(sequelize),
User: User(sequelize),
};
Expand Down
41 changes: 41 additions & 0 deletions lib/database/models/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @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.
*/

const Sequelize = require('sequelize');

module.exports = (sequelize) => {
const Template = sequelize.define('Template', {
name: {
allowNull: false,
unique: true,
type: Sequelize.STRING(64),
},
title: {
allowNull: false,
type: Sequelize.STRING(255),
},
description: {
allowNull: true,
type: Sequelize.TEXT,
},
});

Template.associate = (models) => {
Template.hasMany(models.TemplateModule, {
as: 'modules',
foreignKey: 'templateId',
});
};

return Template;
};
48 changes: 48 additions & 0 deletions lib/database/models/templateModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @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.
*/

const Sequelize = require('sequelize');

module.exports = (sequelize) => {
const TemplateModule = sequelize.define('TemplateModule', {
templateId: {
allowNull: false,
type: Sequelize.INTEGER,
},
position: {
allowNull: false,
type: Sequelize.INTEGER,
},
type: {
allowNull: false,
type: Sequelize.STRING(64),
},
title: {
allowNull: true,
type: Sequelize.STRING(255),
},
options: {
allowNull: false,
type: Sequelize.JSON,
},
});

TemplateModule.associate = (models) => {
TemplateModule.belongsTo(models.Template, {
as: 'template',
foreignKey: 'templateId',
});
};

return TemplateModule;
};
24 changes: 24 additions & 0 deletions lib/database/models/typedefs/SequelizeTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @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.
*/

/**
* @typedef SequelizeTemplate
*
* @property {number} id
* @property {string} name
* @property {string} title
* @property {string|null} description
* @property {SequelizeTemplateModule[]} [modules]
* @property {string} createdAt
* @property {string} updatedAt
*/
25 changes: 25 additions & 0 deletions lib/database/models/typedefs/SequelizeTemplateModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @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.
*/

/**
* @typedef SequelizeTemplateModule
*
* @property {number} id
* @property {number} templateId
* @property {number} position
* @property {string} type
* @property {string|null} title
* @property {Object} options
* @property {string} createdAt
* @property {string} updatedAt
*/
Loading
Loading