179 lines
4.0 KiB
JavaScript
179 lines
4.0 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const DatFiles = db.dat_files;
|
|
|
|
const ExcelFiles = db.excel_files;
|
|
|
|
const ProcessingLogs = db.processing_logs;
|
|
|
|
const DatFilesData = [
|
|
{
|
|
file_name: 'output_1.dat',
|
|
|
|
generated_at: new Date('2023-10-01T15:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
file_name: 'output_2.dat',
|
|
|
|
generated_at: new Date('2023-10-02T16:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
file_name: 'output_3.dat',
|
|
|
|
generated_at: new Date('2023-10-03T17:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
file_name: 'output_4.dat',
|
|
|
|
generated_at: new Date('2023-10-04T18:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const ExcelFilesData = [
|
|
{
|
|
file_name: 'data_input_1.xlsx',
|
|
|
|
uploaded_at: new Date('2023-10-01T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
file_name: 'data_input_2.xlsx',
|
|
|
|
uploaded_at: new Date('2023-10-02T11:00:00Z'),
|
|
},
|
|
|
|
{
|
|
file_name: 'data_input_3.xlsx',
|
|
|
|
uploaded_at: new Date('2023-10-03T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
file_name: 'data_input_4.xlsx',
|
|
|
|
uploaded_at: new Date('2023-10-04T13:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const ProcessingLogsData = [
|
|
{
|
|
log_message: 'File processed successfully.',
|
|
|
|
timestamp: new Date('2023-10-01T15:05:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
log_message: 'Error in data format.',
|
|
|
|
timestamp: new Date('2023-10-02T16:10:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
log_message: 'File processed with warnings.',
|
|
|
|
timestamp: new Date('2023-10-03T17:15:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
log_message: 'File processing started.',
|
|
|
|
timestamp: new Date('2023-10-04T18:20:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateProcessingLogWithRelated_dat_file() {
|
|
const relatedRelated_dat_file0 = await DatFiles.findOne({
|
|
offset: Math.floor(Math.random() * (await DatFiles.count())),
|
|
});
|
|
const ProcessingLog0 = await ProcessingLogs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ProcessingLog0?.setRelated_dat_file) {
|
|
await ProcessingLog0.setRelated_dat_file(relatedRelated_dat_file0);
|
|
}
|
|
|
|
const relatedRelated_dat_file1 = await DatFiles.findOne({
|
|
offset: Math.floor(Math.random() * (await DatFiles.count())),
|
|
});
|
|
const ProcessingLog1 = await ProcessingLogs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ProcessingLog1?.setRelated_dat_file) {
|
|
await ProcessingLog1.setRelated_dat_file(relatedRelated_dat_file1);
|
|
}
|
|
|
|
const relatedRelated_dat_file2 = await DatFiles.findOne({
|
|
offset: Math.floor(Math.random() * (await DatFiles.count())),
|
|
});
|
|
const ProcessingLog2 = await ProcessingLogs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ProcessingLog2?.setRelated_dat_file) {
|
|
await ProcessingLog2.setRelated_dat_file(relatedRelated_dat_file2);
|
|
}
|
|
|
|
const relatedRelated_dat_file3 = await DatFiles.findOne({
|
|
offset: Math.floor(Math.random() * (await DatFiles.count())),
|
|
});
|
|
const ProcessingLog3 = await ProcessingLogs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ProcessingLog3?.setRelated_dat_file) {
|
|
await ProcessingLog3.setRelated_dat_file(relatedRelated_dat_file3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await DatFiles.bulkCreate(DatFilesData);
|
|
|
|
await ExcelFiles.bulkCreate(ExcelFilesData);
|
|
|
|
await ProcessingLogs.bulkCreate(ProcessingLogsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProcessingLogWithRelated_dat_file(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('dat_files', null, {});
|
|
|
|
await queryInterface.bulkDelete('excel_files', null, {});
|
|
|
|
await queryInterface.bulkDelete('processing_logs', null, {});
|
|
},
|
|
};
|