Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[O2B-1100] Delete subsystems #1433

Merged
merged 12 commits into from
Jul 25, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/bookkeeping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
logs,
envs,
runs,
subsystems,
tags,
flps,
home,
Expand Down
8 changes: 0 additions & 8 deletions lib/database/adapters/LogAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ class LogAdapter {
*/
this.environmentAdapter = null;

/**
* @type {SubsystemAdapter|null}
*/
this.subsystemAdapter = null;

/**
* @type {TagAdapter|null}
*/
Expand Down Expand Up @@ -79,14 +74,12 @@ class LogAdapter {
tags: sequelizeTags,
runs,
lhcFills: sequelizeLhcFills,
subsystems: sequelizeSubsytems,
attachments: sequelizeAttachments,
environments: sequelizeEnvironments,
} = databaseObject;

const minifiedRuns = (runs || []).map(this.runAdapter.toMinifiedEntity);
const tags = (sequelizeTags || []).map(this.tagAdapter.toEntity);
const subsystems = (sequelizeSubsytems || []).map(this.subsystemAdapter.toEntity);
const attachments = (sequelizeAttachments || []).map(this.attachmentAdapter.toEntity);
const lhcFills = (sequelizeLhcFills || []).map(this.lhcFillAdapter.toEntity);
const environments = (sequelizeEnvironments || []).map(this.environmentAdapter.toEntity);
Expand All @@ -104,7 +97,6 @@ class LogAdapter {
runs: minifiedRuns,
tags,
lhcFills,
subsystems,
attachments,
environments,
};
Expand Down
47 changes: 0 additions & 47 deletions lib/database/adapters/SubsystemAdapter.js

This file was deleted.

4 changes: 0 additions & 4 deletions lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const RunDetectorsAdapter = require('./RunDetectorsAdapter');
const RunTypeAdapter = require('./RunTypeAdapter');
const SimulationPassAdapter = require('./SimulationPassAdapter.js');
const { SimulationPassQcFlagAdapter } = require('./SimulationPassQcFlagAdapter');
const SubsystemAdapter = require('./SubsystemAdapter');
const TagAdapter = require('./TagAdapter');
const { TriggerCountersAdapter } = require('./TriggerCountersAdapter');
const UserAdapter = require('./UserAdapter');
Expand Down Expand Up @@ -80,7 +79,6 @@ const runDetectorsAdapter = new RunDetectorsAdapter();
const runTypeAdapter = new RunTypeAdapter();
const simulationPassAdapter = new SimulationPassAdapter();
const simulationPassQcFlagAdapter = new SimulationPassQcFlagAdapter();
const subsystemAdapter = new SubsystemAdapter();
const tagAdapter = new TagAdapter();
const triggerCountersAdapter = new TriggerCountersAdapter();
const userAdapter = new UserAdapter();
Expand Down Expand Up @@ -118,7 +116,6 @@ logAdapter.attachmentAdapter = attachmentAdapter;
logAdapter.environmentAdapter = environmentAdapter;
logAdapter.lhcFillAdapter = lhcFillAdapter;
logAdapter.runAdapter = runAdapter;
logAdapter.subsystemAdapter = subsystemAdapter;
logAdapter.tagAdapter = tagAdapter;
logAdapter.userAdapter = userAdapter;

Expand Down Expand Up @@ -175,7 +172,6 @@ module.exports = {
runTypeAdapter,
simulationPassAdapter,
simulationPassQcFlagAdapter,
subsystemAdapter,
tagAdapter,
triggerCountersAdapter,
userAdapter,
Expand Down
103 changes: 103 additions & 0 deletions lib/database/migrations/20240430100347-delete-subsystems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
'use strict';

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

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
const [{ count }] = await queryInterface.sequelize.query(
'SELECT COUNT(*) count FROM subsystems',
{ type: QueryTypes.SELECT, transaction, raw: true },
);

// Put a security to avoid dropping subsystems if the table is not empty
if (parseInt(count, 10)) {
throw new Error('Subsystems table is not empty.' +
' If the table is filled with seeders, please manually truncate it then re-run migrations');
}

// Transition all logs with "subsystem" type to "comment"
await queryInterface.sequelize.query(
'UPDATE logs SET subtype=\'comment\' WHERE subtype=\'subsystem\'',
{ transaction, raw: true },
);
await queryInterface.changeColumn('logs', 'subtype', {
allowNull: false,
type: Sequelize.ENUM('run', 'announcement', 'intervention', 'comment'),
});

await queryInterface.dropTable('log_subsystems', { transaction });
await queryInterface.dropTable('subsystems', { transaction });
}),

down: async (queryInterface, Sequelize) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.createTable('subsystems', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
name: {
allowNull: false,
type: Sequelize.STRING,
},
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('log_subsystems', {
log_id: {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
},
subsystem_id: {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
},
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 })
.then(() => queryInterface.addConstraint('log_subsystems', {
fields: ['log_id'],
type: 'foreign key',
name: 'fk_log_id_log_subsystems',
references: {
table: 'logs',
field: 'id',
},
xsalonx marked this conversation as resolved.
Show resolved Hide resolved
}, { transaction }))
.then(() => queryInterface.addConstraint('log_subsystems', {
fields: ['subsystem_id'],
type: 'foreign key',
name: 'fk_subsystem_id_log_subsystems',
references: {
table: 'subsystems',
field: 'id',
},
}, { transaction }));

await queryInterface.changeColumn('logs', 'subtype', {
allowNull: false,
type: Sequelize.ENUM('run', 'subsystem', 'announcement', 'intervention', 'comment'),
});
}),
};
2 changes: 0 additions & 2 deletions lib/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const RunType = require('./runType');
const SimulationPass = require('./simulationPass.js');
const SimulationPassQcFlag = require('./simulationPassQcFlag.js');
const StableBeamRun = require('./stableBeamsRun.js');
const Subsystem = require('./subsystem');
const Tag = require('./tag');
const TriggerCounters = require('./triggerCounters');
const User = require('./user');
Expand Down Expand Up @@ -82,7 +81,6 @@ module.exports = (sequelize) => {
SimulationPass: SimulationPass(sequelize),
SimulationPassQcFlag: SimulationPassQcFlag(sequelize),
StableBeamRun: StableBeamRun(sequelize),
Subsystem: Subsystem(sequelize),
Tag: Tag(sequelize),
TriggerCounters: TriggerCounters(sequelize),
User: User(sequelize),
Expand Down
3 changes: 1 addition & 2 deletions lib/database/models/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = (sequelize) => {
},
subtype: {
allowNull: false,
type: Sequelize.ENUM('run', 'subsystem', 'announcement', 'intervention', 'comment'),
type: Sequelize.ENUM('run', 'announcement', 'intervention', 'comment'),
},
origin: {
allowNull: false,
Expand Down Expand Up @@ -55,7 +55,6 @@ module.exports = (sequelize) => {
Log.belongsToMany(models.Run, { as: 'runs', through: 'log_runs' });
Log.belongsToMany(models.Tag, { as: 'tags', through: 'log_tags' });
Log.belongsToMany(models.Environment, { as: 'environments', through: 'log_environments' });
Log.belongsToMany(models.Subsystem, { as: 'subsystems', through: 'log_subsystems' });
graduta marked this conversation as resolved.
Show resolved Hide resolved
Log.belongsToMany(models.LhcFill, { as: 'lhcFills', through: 'log_lhc_fills', foreignKey: 'log_id' });

Log.hasMany(models.Attachment, { as: 'attachments', foreignKey: 'log_id' });
Expand Down
28 changes: 0 additions & 28 deletions lib/database/models/subsystem.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/database/models/typedefs/SequelizeLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @property {SequelizeLog|null} parentLog
* @property {SequelizeRun[]|null} runs
* @property {SequelizeTag[]|null} tags
* @property {SequelizeSubsystem[]|null} subsystems
* @property {SequelizeAttachment[]|null} attachments
* @property {SequelizeEnvironment[]|null} environments
*/
21 changes: 0 additions & 21 deletions lib/database/models/typedefs/SequelizeSubsystem.js

This file was deleted.

17 changes: 0 additions & 17 deletions lib/database/repositories/LogRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,6 @@ class LogRepository extends Repository {
return this.findAll(queryBuilder);
}

/**
* Returns all entities.
*
* @param {Object} subsystemId The QueryBuilder to use.
* @param {QueryBuilder} queryBuilder The QueryBuilder to use.
* @returns {Promise} Promise object representing the full mock data
*/
async findAllBySubsystemId(subsystemId, queryBuilder = new QueryBuilder()) {
queryBuilder
.setModel(Log)
.include('user')
.include('tags')
.whereAssociation('subsystems', 'id').is(subsystemId);

return this.findAll(queryBuilder);
}

/**
* Returns the list of tags and their occurrences in the logs created in the given period
*
Expand Down
33 changes: 0 additions & 33 deletions lib/database/repositories/SubsystemRepository.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/database/repositories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const RunTypeRepository = require('./RunTypeRepository');
const SimulationPassRepository = require('./SimulationPassRepository.js');
const SimulationPassQcFlagRepository = require('./SimulationPassQcFlagRepository.js');
const StableBeamRunsRepository = require('./StableBeamRunsRepository.js');
const SubsystemRepository = require('./SubsystemRepository');
const TagRepository = require('./TagRepository');
const TriggerCountersRepository = require('./TriggerCountersRepository');
const UserRepository = require('./UserRepository');
Expand Down Expand Up @@ -89,7 +88,6 @@ module.exports = {
SimulationPassRepository,
SimulationPassQcFlagRepository,
StableBeamRunsRepository,
SubsystemRepository,
TagRepository,
TriggerCountersRepository,
UserRepository,
Expand Down
Loading
Loading