398 lines
8.7 KiB
JavaScript
398 lines
8.7 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Assets = db.assets;
|
|
|
|
const Buildings = db.buildings;
|
|
|
|
const WorkOrders = db.work_orders;
|
|
|
|
const AssetsData = [
|
|
{
|
|
asset_name: 'Main Pump',
|
|
|
|
asset_type: 'Sensor',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
asset_name: 'Cooling Valve',
|
|
|
|
asset_type: 'Pump',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
asset_name: 'Temperature Sensor',
|
|
|
|
asset_type: 'Motor',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
asset_name: 'Conveyor Motor',
|
|
|
|
asset_type: 'Motor',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
asset_name: 'Backup Generator',
|
|
|
|
asset_type: 'Sensor',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const BuildingsData = [
|
|
{
|
|
name: 'Central Office',
|
|
|
|
location: 'Downtown',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'North Facility',
|
|
|
|
location: 'Uptown',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'East Plant',
|
|
|
|
location: 'Industrial Park',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'West Warehouse',
|
|
|
|
location: 'Suburban Area',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'South Depot',
|
|
|
|
location: 'Riverside',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const WorkOrdersData = [
|
|
{
|
|
description: 'Replace worn-out pump seals',
|
|
|
|
start_date: new Date('2023-11-01T08:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-01T12:00:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Calibrate temperature sensor',
|
|
|
|
start_date: new Date('2023-11-02T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-02T11:00:00Z'),
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Inspect cooling valve',
|
|
|
|
start_date: new Date('2023-11-03T10:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-03T14:00:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Test backup generator',
|
|
|
|
start_date: new Date('2023-11-04T13:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-04T15:00:00Z'),
|
|
|
|
status: 'InProgress',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
description: 'Lubricate conveyor motor',
|
|
|
|
start_date: new Date('2023-11-05T07:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-05T09:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateAssetWithBuilding() {
|
|
const relatedBuilding0 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const Asset0 = await Assets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Asset0?.setBuilding) {
|
|
await Asset0.setBuilding(relatedBuilding0);
|
|
}
|
|
|
|
const relatedBuilding1 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const Asset1 = await Assets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Asset1?.setBuilding) {
|
|
await Asset1.setBuilding(relatedBuilding1);
|
|
}
|
|
|
|
const relatedBuilding2 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const Asset2 = await Assets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Asset2?.setBuilding) {
|
|
await Asset2.setBuilding(relatedBuilding2);
|
|
}
|
|
|
|
const relatedBuilding3 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const Asset3 = await Assets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Asset3?.setBuilding) {
|
|
await Asset3.setBuilding(relatedBuilding3);
|
|
}
|
|
|
|
const relatedBuilding4 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const Asset4 = await Assets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Asset4?.setBuilding) {
|
|
await Asset4.setBuilding(relatedBuilding4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateWorkOrderWithAsset() {
|
|
const relatedAsset0 = await Assets.findOne({
|
|
offset: Math.floor(Math.random() * (await Assets.count())),
|
|
});
|
|
const WorkOrder0 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (WorkOrder0?.setAsset) {
|
|
await WorkOrder0.setAsset(relatedAsset0);
|
|
}
|
|
|
|
const relatedAsset1 = await Assets.findOne({
|
|
offset: Math.floor(Math.random() * (await Assets.count())),
|
|
});
|
|
const WorkOrder1 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (WorkOrder1?.setAsset) {
|
|
await WorkOrder1.setAsset(relatedAsset1);
|
|
}
|
|
|
|
const relatedAsset2 = await Assets.findOne({
|
|
offset: Math.floor(Math.random() * (await Assets.count())),
|
|
});
|
|
const WorkOrder2 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (WorkOrder2?.setAsset) {
|
|
await WorkOrder2.setAsset(relatedAsset2);
|
|
}
|
|
|
|
const relatedAsset3 = await Assets.findOne({
|
|
offset: Math.floor(Math.random() * (await Assets.count())),
|
|
});
|
|
const WorkOrder3 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (WorkOrder3?.setAsset) {
|
|
await WorkOrder3.setAsset(relatedAsset3);
|
|
}
|
|
|
|
const relatedAsset4 = await Assets.findOne({
|
|
offset: Math.floor(Math.random() * (await Assets.count())),
|
|
});
|
|
const WorkOrder4 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (WorkOrder4?.setAsset) {
|
|
await WorkOrder4.setAsset(relatedAsset4);
|
|
}
|
|
}
|
|
|
|
async function associateWorkOrderWithBuilding() {
|
|
const relatedBuilding0 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const WorkOrder0 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (WorkOrder0?.setBuilding) {
|
|
await WorkOrder0.setBuilding(relatedBuilding0);
|
|
}
|
|
|
|
const relatedBuilding1 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const WorkOrder1 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (WorkOrder1?.setBuilding) {
|
|
await WorkOrder1.setBuilding(relatedBuilding1);
|
|
}
|
|
|
|
const relatedBuilding2 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const WorkOrder2 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (WorkOrder2?.setBuilding) {
|
|
await WorkOrder2.setBuilding(relatedBuilding2);
|
|
}
|
|
|
|
const relatedBuilding3 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const WorkOrder3 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (WorkOrder3?.setBuilding) {
|
|
await WorkOrder3.setBuilding(relatedBuilding3);
|
|
}
|
|
|
|
const relatedBuilding4 = await Buildings.findOne({
|
|
offset: Math.floor(Math.random() * (await Buildings.count())),
|
|
});
|
|
const WorkOrder4 = await WorkOrders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (WorkOrder4?.setBuilding) {
|
|
await WorkOrder4.setBuilding(relatedBuilding4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Assets.bulkCreate(AssetsData);
|
|
|
|
await Buildings.bulkCreate(BuildingsData);
|
|
|
|
await WorkOrders.bulkCreate(WorkOrdersData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateAssetWithBuilding(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateWorkOrderWithAsset(),
|
|
|
|
await associateWorkOrderWithBuilding(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('assets', null, {});
|
|
|
|
await queryInterface.bulkDelete('buildings', null, {});
|
|
|
|
await queryInterface.bulkDelete('work_orders', null, {});
|
|
},
|
|
};
|