Skip to content

Commit

Permalink
[O2B-1092] add migration file (#1313)
Browse files Browse the repository at this point in the history
* add migration file

* add model, fix outputsize type

* add typedef

* rename
  • Loading branch information
xsalonx authored Dec 20, 2023
1 parent ca7eaa2 commit 0b799dd
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/database/migrations/20231211080706-create-data-passes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.createTable('data_passes', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
description: {
type: Sequelize.TEXT,
},
output_size: {
type: Sequelize.BIGINT,
},
reconstructed_events_count: {
type: Sequelize.INTEGER,
},
last_run_number: {
type: Sequelize.INTEGER,
},
lhc_period_id: {
type: Sequelize.INTEGER,
references: {
model: 'lhc_periods',
key: 'id',
},
},
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 });
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.dropTable('data_passes', { transaction });
}),
};
51 changes: 51 additions & 0 deletions lib/database/models/dataPass.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.
*/

const Sequelize = require('sequelize');

module.exports = (sequelize) => {
const DataPass = sequelize.define(
'DataPass',
{
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
description: {
type: Sequelize.TEXT,
},
outputSize: {
type: Sequelize.BIGINT,
},
reconstructedEventsCount: {
type: Sequelize.INTEGER,
},
lastRunNumber: {
type: Sequelize.INTEGER,
},
},
{ tableName: 'data_passes' },
);

DataPass.associate = (models) => {
DataPass.belongsTo(models.LhcPeriod, { foreignKey: 'lhcPeriodId', as: 'lhcPeriod' });
};

return DataPass;
};
2 changes: 2 additions & 0 deletions lib/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Tag = require('./tag');
const User = require('./user');
const LhcPeriod = require('./lhcPeriod');
const LhcPeriodStatistics = require('./lhcPeriodsStatistics');
const DataPass = require('./dataPass.js');

module.exports = (sequelize) => {
const models = {
Expand Down Expand Up @@ -64,6 +65,7 @@ module.exports = (sequelize) => {
User: User(sequelize),
LhcPeriod: LhcPeriod(sequelize),
LhcPeriodStatistics: LhcPeriodStatistics(sequelize),
DataPass: DataPass(sequelize),
};

Object.entries(models).forEach(([_key, model]) => {
Expand Down
1 change: 1 addition & 0 deletions lib/database/models/lhcPeriod.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = (sequelize) => {

LhcPeriod.associate = (models) => {
LhcPeriod.hasMany(models.Run, { foreignKey: 'lhcPeriodId', as: 'runs' });
LhcPeriod.hasOne(models.DataPass);
};

return LhcPeriod;
Expand Down
23 changes: 23 additions & 0 deletions lib/database/models/typedefs/SequelizeDataPass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @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 SequelizeDataPass
*
* @property {number} id
* @property {string} name
* @property {string} description
* @property {number} outputSize
* @property {number} reconstructedEventsCount
* @property {number} lastRunNumber
*/

0 comments on commit 0b799dd

Please sign in to comment.