755 lines
17 KiB
JavaScript
755 lines
17 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Alerts = db.alerts;
|
|
|
|
const Assignments = db.assignments;
|
|
|
|
const Docks = db.docks;
|
|
|
|
const Inventory = db.inventory;
|
|
|
|
const Items = db.items;
|
|
|
|
const Routes = db.routes;
|
|
|
|
const Trucks = db.trucks;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const AlertsData = [
|
|
{
|
|
alert_type: 'Delay',
|
|
|
|
description: 'Truck TRK001 delayed due to traffic',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
alert_type: 'Maintenance',
|
|
|
|
description: 'Dock-3 under maintenance',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
alert_type: 'Safety',
|
|
|
|
description: 'Safety breach at Dock-2',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const AssignmentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
assigned_at: new Date('2023-11-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
assigned_at: new Date('2023-11-01T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
assigned_at: new Date('2023-11-01T13:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const DocksData = [
|
|
{
|
|
dock_name: 'Dock-1',
|
|
|
|
status: 'available',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
dock_name: 'Dock-2',
|
|
|
|
status: 'available',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
dock_name: 'Dock-3',
|
|
|
|
status: 'maintenance',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const InventoryData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 100,
|
|
|
|
warehouse_location: 'Warehouse-1',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 200,
|
|
|
|
warehouse_location: 'Warehouse-2',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 50,
|
|
|
|
warehouse_location: 'Warehouse-3',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ItemsData = [
|
|
{
|
|
sku: 'SKU123',
|
|
|
|
location: 'Zone-A',
|
|
|
|
status: 'damaged',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
sku: 'SKU456',
|
|
|
|
location: 'Zone-B',
|
|
|
|
status: 'damaged',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
sku: 'SKU789',
|
|
|
|
location: 'Zone-C',
|
|
|
|
status: 'in_transit',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const RoutesData = [
|
|
{
|
|
origin: 'Haryana',
|
|
|
|
destination: 'Delhi',
|
|
|
|
estimated_arrival: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
origin: 'Delhi',
|
|
|
|
destination: 'Ranchi',
|
|
|
|
estimated_arrival: new Date('2023-11-02T15:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
origin: 'Noida',
|
|
|
|
destination: 'Gurgaon',
|
|
|
|
estimated_arrival: new Date('2023-11-01T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TrucksData = [
|
|
{
|
|
truck_id: 'TRK001',
|
|
|
|
status: 'enroute',
|
|
|
|
lat: 28.6139,
|
|
|
|
lng: 77.209,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
truck_id: 'TRK002',
|
|
|
|
status: 'loading',
|
|
|
|
lat: 28.7041,
|
|
|
|
lng: 77.1025,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
truck_id: 'TRK003',
|
|
|
|
status: 'unloading',
|
|
|
|
lat: 28.5355,
|
|
|
|
lng: 77.391,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'J. Robert Oppenheimer',
|
|
},
|
|
|
|
{
|
|
name: 'Joseph J. Thomson',
|
|
},
|
|
|
|
{
|
|
name: 'B. F. Skinner',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setOrganization) {
|
|
await User0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setOrganization) {
|
|
await User1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setOrganization) {
|
|
await User2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateAlertWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Alert0 = await Alerts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Alert0?.setOrganization) {
|
|
await Alert0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Alert1 = await Alerts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Alert1?.setOrganization) {
|
|
await Alert1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Alert2 = await Alerts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Alert2?.setOrganization) {
|
|
await Alert2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateAssignmentWithTruck() {
|
|
const relatedTruck0 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const Assignment0 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Assignment0?.setTruck) {
|
|
await Assignment0.setTruck(relatedTruck0);
|
|
}
|
|
|
|
const relatedTruck1 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const Assignment1 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Assignment1?.setTruck) {
|
|
await Assignment1.setTruck(relatedTruck1);
|
|
}
|
|
|
|
const relatedTruck2 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const Assignment2 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Assignment2?.setTruck) {
|
|
await Assignment2.setTruck(relatedTruck2);
|
|
}
|
|
}
|
|
|
|
async function associateAssignmentWithDock() {
|
|
const relatedDock0 = await Docks.findOne({
|
|
offset: Math.floor(Math.random() * (await Docks.count())),
|
|
});
|
|
const Assignment0 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Assignment0?.setDock) {
|
|
await Assignment0.setDock(relatedDock0);
|
|
}
|
|
|
|
const relatedDock1 = await Docks.findOne({
|
|
offset: Math.floor(Math.random() * (await Docks.count())),
|
|
});
|
|
const Assignment1 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Assignment1?.setDock) {
|
|
await Assignment1.setDock(relatedDock1);
|
|
}
|
|
|
|
const relatedDock2 = await Docks.findOne({
|
|
offset: Math.floor(Math.random() * (await Docks.count())),
|
|
});
|
|
const Assignment2 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Assignment2?.setDock) {
|
|
await Assignment2.setDock(relatedDock2);
|
|
}
|
|
}
|
|
|
|
async function associateAssignmentWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Assignment0 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Assignment0?.setOrganization) {
|
|
await Assignment0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Assignment1 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Assignment1?.setOrganization) {
|
|
await Assignment1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Assignment2 = await Assignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Assignment2?.setOrganization) {
|
|
await Assignment2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateDockWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Dock0 = await Docks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Dock0?.setOrganization) {
|
|
await Dock0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Dock1 = await Docks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Dock1?.setOrganization) {
|
|
await Dock1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Dock2 = await Docks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Dock2?.setOrganization) {
|
|
await Dock2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateInventoryWithItem() {
|
|
const relatedItem0 = await Items.findOne({
|
|
offset: Math.floor(Math.random() * (await Items.count())),
|
|
});
|
|
const Inventory0 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Inventory0?.setItem) {
|
|
await Inventory0.setItem(relatedItem0);
|
|
}
|
|
|
|
const relatedItem1 = await Items.findOne({
|
|
offset: Math.floor(Math.random() * (await Items.count())),
|
|
});
|
|
const Inventory1 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Inventory1?.setItem) {
|
|
await Inventory1.setItem(relatedItem1);
|
|
}
|
|
|
|
const relatedItem2 = await Items.findOne({
|
|
offset: Math.floor(Math.random() * (await Items.count())),
|
|
});
|
|
const Inventory2 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Inventory2?.setItem) {
|
|
await Inventory2.setItem(relatedItem2);
|
|
}
|
|
}
|
|
|
|
async function associateInventoryWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Inventory0 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Inventory0?.setOrganization) {
|
|
await Inventory0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Inventory1 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Inventory1?.setOrganization) {
|
|
await Inventory1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Inventory2 = await Inventory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Inventory2?.setOrganization) {
|
|
await Inventory2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateItemWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Item0 = await Items.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Item0?.setOrganization) {
|
|
await Item0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Item1 = await Items.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Item1?.setOrganization) {
|
|
await Item1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Item2 = await Items.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Item2?.setOrganization) {
|
|
await Item2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateRouteWithTruck() {
|
|
const relatedTruck0 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const Route0 = await Routes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Route0?.setTruck) {
|
|
await Route0.setTruck(relatedTruck0);
|
|
}
|
|
|
|
const relatedTruck1 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const Route1 = await Routes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Route1?.setTruck) {
|
|
await Route1.setTruck(relatedTruck1);
|
|
}
|
|
|
|
const relatedTruck2 = await Trucks.findOne({
|
|
offset: Math.floor(Math.random() * (await Trucks.count())),
|
|
});
|
|
const Route2 = await Routes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Route2?.setTruck) {
|
|
await Route2.setTruck(relatedTruck2);
|
|
}
|
|
}
|
|
|
|
async function associateRouteWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Route0 = await Routes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Route0?.setOrganization) {
|
|
await Route0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Route1 = await Routes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Route1?.setOrganization) {
|
|
await Route1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Route2 = await Routes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Route2?.setOrganization) {
|
|
await Route2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateTruckWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Truck0 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Truck0?.setOrganization) {
|
|
await Truck0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Truck1 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Truck1?.setOrganization) {
|
|
await Truck1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Truck2 = await Trucks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Truck2?.setOrganization) {
|
|
await Truck2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Alerts.bulkCreate(AlertsData);
|
|
|
|
await Assignments.bulkCreate(AssignmentsData);
|
|
|
|
await Docks.bulkCreate(DocksData);
|
|
|
|
await Inventory.bulkCreate(InventoryData);
|
|
|
|
await Items.bulkCreate(ItemsData);
|
|
|
|
await Routes.bulkCreate(RoutesData);
|
|
|
|
await Trucks.bulkCreate(TrucksData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateAlertWithOrganization(),
|
|
|
|
await associateAssignmentWithTruck(),
|
|
|
|
await associateAssignmentWithDock(),
|
|
|
|
await associateAssignmentWithOrganization(),
|
|
|
|
await associateDockWithOrganization(),
|
|
|
|
await associateInventoryWithItem(),
|
|
|
|
await associateInventoryWithOrganization(),
|
|
|
|
await associateItemWithOrganization(),
|
|
|
|
await associateRouteWithTruck(),
|
|
|
|
await associateRouteWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTruckWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('alerts', null, {});
|
|
|
|
await queryInterface.bulkDelete('assignments', null, {});
|
|
|
|
await queryInterface.bulkDelete('docks', null, {});
|
|
|
|
await queryInterface.bulkDelete('inventory', null, {});
|
|
|
|
await queryInterface.bulkDelete('items', null, {});
|
|
|
|
await queryInterface.bulkDelete('routes', null, {});
|
|
|
|
await queryInterface.bulkDelete('trucks', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|