32501/backend/src/db/seeders/20231127130745-sample-data.js
2025-06-27 14:18:03 +00:00

939 lines
22 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const HumanResources = db.human_resources;
const Inventory = db.inventory;
const Machinery = db.machinery;
const QualityControl = db.quality_control;
const RawMaterials = db.raw_materials;
const Suppliers = db.suppliers;
const WorkOrders = db.work_orders;
const Organizations = db.organizations;
const HumanResourcesData = [
{
employee_name: 'John Doe',
role: 'Production Manager',
shift: 'Day',
payroll: 75000,
// type code here for "relation_one" field
},
{
employee_name: 'Alice Smith',
role: 'Inventory Clerk',
shift: 'Night',
payroll: 50000,
// type code here for "relation_one" field
},
{
employee_name: 'Bob White',
role: 'Maintenance Engineer',
shift: 'Day',
payroll: 60000,
// type code here for "relation_one" field
},
{
employee_name: 'Charlie Green',
role: 'Production Manager',
shift: 'Day',
payroll: 75000,
// type code here for "relation_one" field
},
];
const InventoryData = [
{
product_name: 'Steel Beams',
quantity_available: 2000,
quantity_reserved: 500,
quantity_returned: 100,
// type code here for "relation_one" field
},
{
product_name: 'Aluminum Sheets',
quantity_available: 1500,
quantity_reserved: 300,
quantity_returned: 50,
// type code here for "relation_one" field
},
{
product_name: 'Copper Tubes',
quantity_available: 1000,
quantity_reserved: 200,
quantity_returned: 30,
// type code here for "relation_one" field
},
{
product_name: 'Plastic Molds',
quantity_available: 5000,
quantity_reserved: 1000,
quantity_returned: 200,
// type code here for "relation_one" field
},
];
const MachineryData = [
{
machine_name: 'Lathe Machine',
model: 'LM-200',
maintenance_schedule: new Date('2023-11-01T10:00:00Z'),
is_operational: true,
// type code here for "relation_one" field
},
{
machine_name: 'Injection Molder',
model: 'IM-450',
maintenance_schedule: new Date('2023-11-05T10:00:00Z'),
is_operational: true,
// type code here for "relation_one" field
},
{
machine_name: 'Press Machine',
model: 'PM-300',
maintenance_schedule: new Date('2023-11-10T10:00:00Z'),
is_operational: true,
// type code here for "relation_one" field
},
{
machine_name: 'CNC Machine',
model: 'CNC-500',
maintenance_schedule: new Date('2023-11-15T10:00:00Z'),
is_operational: true,
// type code here for "relation_one" field
},
];
const QualityControlData = [
{
check_name: 'Initial Inspection',
// type code here for "relation_one" field
check_date: new Date('2023-10-02T09:00:00Z'),
passed: true,
// type code here for "relation_one" field
},
{
check_name: 'Mid-Production Check',
// type code here for "relation_one" field
check_date: new Date('2023-10-07T09:00:00Z'),
passed: true,
// type code here for "relation_one" field
},
{
check_name: 'Final Inspection',
// type code here for "relation_one" field
check_date: new Date('2023-10-12T09:00:00Z'),
passed: true,
// type code here for "relation_one" field
},
{
check_name: 'Random Check',
// type code here for "relation_one" field
check_date: new Date('2023-10-17T09:00:00Z'),
passed: true,
// type code here for "relation_one" field
},
];
const RawMaterialsData = [
{
name: 'Steel Sheets',
quantity: 5000,
reorder_level: 1000,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Aluminum Rods',
quantity: 3000,
reorder_level: 500,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Copper Wires',
quantity: 2000,
reorder_level: 300,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Plastic Pellets',
quantity: 10000,
reorder_level: 2000,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const SuppliersData = [
{
supplier_name: 'SteelCo',
contract_terms: 'Annual contract with quarterly reviews',
delivery_schedule: new Date('2023-10-15T10:00:00Z'),
payment_due: 50000,
// type code here for "relation_one" field
},
{
supplier_name: 'AluSupply',
contract_terms: 'Bi-annual contract with monthly deliveries',
delivery_schedule: new Date('2023-10-20T10:00:00Z'),
payment_due: 30000,
// type code here for "relation_one" field
},
{
supplier_name: 'CopperWorld',
contract_terms: 'Monthly contract with weekly deliveries',
delivery_schedule: new Date('2023-10-25T10:00:00Z'),
payment_due: 20000,
// type code here for "relation_one" field
},
{
supplier_name: 'Plastics Inc.',
contract_terms: 'Annual contract with bi-monthly deliveries',
delivery_schedule: new Date('2023-10-30T10:00:00Z'),
payment_due: 40000,
// type code here for "relation_one" field
},
];
const WorkOrdersData = [
{
order_number: 'WO-001',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
start_date: new Date('2023-10-01T08:00:00Z'),
end_date: new Date('2023-10-05T17:00:00Z'),
// type code here for "relation_one" field
},
{
order_number: 'WO-002',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
start_date: new Date('2023-10-06T08:00:00Z'),
end_date: new Date('2023-10-10T17:00:00Z'),
// type code here for "relation_one" field
},
{
order_number: 'WO-003',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
start_date: new Date('2023-10-11T08:00:00Z'),
end_date: new Date('2023-10-15T17:00:00Z'),
// type code here for "relation_one" field
},
{
order_number: 'WO-004',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
start_date: new Date('2023-10-16T08:00:00Z'),
end_date: new Date('2023-10-20T17:00:00Z'),
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Paul Ehrlich',
},
{
name: 'J. Robert Oppenheimer',
},
{
name: 'Comte de Buffon',
},
{
name: 'Alfred Kinsey',
},
];
// 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);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setOrganization) {
await User3.setOrganization(relatedOrganization3);
}
}
async function associateHumanResourceWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const HumanResource0 = await HumanResources.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (HumanResource0?.setOrganization) {
await HumanResource0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const HumanResource1 = await HumanResources.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (HumanResource1?.setOrganization) {
await HumanResource1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const HumanResource2 = await HumanResources.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (HumanResource2?.setOrganization) {
await HumanResource2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const HumanResource3 = await HumanResources.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (HumanResource3?.setOrganization) {
await HumanResource3.setOrganization(relatedOrganization3);
}
}
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);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Inventory3 = await Inventory.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Inventory3?.setOrganization) {
await Inventory3.setOrganization(relatedOrganization3);
}
}
async function associateMachineryWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Machinery0 = await Machinery.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Machinery0?.setOrganization) {
await Machinery0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Machinery1 = await Machinery.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Machinery1?.setOrganization) {
await Machinery1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Machinery2 = await Machinery.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Machinery2?.setOrganization) {
await Machinery2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Machinery3 = await Machinery.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Machinery3?.setOrganization) {
await Machinery3.setOrganization(relatedOrganization3);
}
}
async function associateQualityControlWithWork_order() {
const relatedWork_order0 = await WorkOrders.findOne({
offset: Math.floor(Math.random() * (await WorkOrders.count())),
});
const QualityControl0 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (QualityControl0?.setWork_order) {
await QualityControl0.setWork_order(relatedWork_order0);
}
const relatedWork_order1 = await WorkOrders.findOne({
offset: Math.floor(Math.random() * (await WorkOrders.count())),
});
const QualityControl1 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (QualityControl1?.setWork_order) {
await QualityControl1.setWork_order(relatedWork_order1);
}
const relatedWork_order2 = await WorkOrders.findOne({
offset: Math.floor(Math.random() * (await WorkOrders.count())),
});
const QualityControl2 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (QualityControl2?.setWork_order) {
await QualityControl2.setWork_order(relatedWork_order2);
}
const relatedWork_order3 = await WorkOrders.findOne({
offset: Math.floor(Math.random() * (await WorkOrders.count())),
});
const QualityControl3 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (QualityControl3?.setWork_order) {
await QualityControl3.setWork_order(relatedWork_order3);
}
}
async function associateQualityControlWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const QualityControl0 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (QualityControl0?.setOrganization) {
await QualityControl0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const QualityControl1 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (QualityControl1?.setOrganization) {
await QualityControl1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const QualityControl2 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (QualityControl2?.setOrganization) {
await QualityControl2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const QualityControl3 = await QualityControl.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (QualityControl3?.setOrganization) {
await QualityControl3.setOrganization(relatedOrganization3);
}
}
// Similar logic for "relation_many"
async function associateRawMaterialWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const RawMaterial0 = await RawMaterials.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (RawMaterial0?.setOrganization) {
await RawMaterial0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const RawMaterial1 = await RawMaterials.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (RawMaterial1?.setOrganization) {
await RawMaterial1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const RawMaterial2 = await RawMaterials.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (RawMaterial2?.setOrganization) {
await RawMaterial2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const RawMaterial3 = await RawMaterials.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (RawMaterial3?.setOrganization) {
await RawMaterial3.setOrganization(relatedOrganization3);
}
}
async function associateSupplierWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Supplier0 = await Suppliers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Supplier0?.setOrganization) {
await Supplier0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Supplier1 = await Suppliers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Supplier1?.setOrganization) {
await Supplier1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Supplier2 = await Suppliers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Supplier2?.setOrganization) {
await Supplier2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Supplier3 = await Suppliers.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Supplier3?.setOrganization) {
await Supplier3.setOrganization(relatedOrganization3);
}
}
async function associateWorkOrderWithProduction_manager() {
const relatedProduction_manager0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WorkOrder0 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (WorkOrder0?.setProduction_manager) {
await WorkOrder0.setProduction_manager(relatedProduction_manager0);
}
const relatedProduction_manager1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WorkOrder1 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (WorkOrder1?.setProduction_manager) {
await WorkOrder1.setProduction_manager(relatedProduction_manager1);
}
const relatedProduction_manager2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WorkOrder2 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (WorkOrder2?.setProduction_manager) {
await WorkOrder2.setProduction_manager(relatedProduction_manager2);
}
const relatedProduction_manager3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WorkOrder3 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (WorkOrder3?.setProduction_manager) {
await WorkOrder3.setProduction_manager(relatedProduction_manager3);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateWorkOrderWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const WorkOrder0 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (WorkOrder0?.setOrganization) {
await WorkOrder0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const WorkOrder1 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (WorkOrder1?.setOrganization) {
await WorkOrder1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const WorkOrder2 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (WorkOrder2?.setOrganization) {
await WorkOrder2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const WorkOrder3 = await WorkOrders.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (WorkOrder3?.setOrganization) {
await WorkOrder3.setOrganization(relatedOrganization3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await HumanResources.bulkCreate(HumanResourcesData);
await Inventory.bulkCreate(InventoryData);
await Machinery.bulkCreate(MachineryData);
await QualityControl.bulkCreate(QualityControlData);
await RawMaterials.bulkCreate(RawMaterialsData);
await Suppliers.bulkCreate(SuppliersData);
await WorkOrders.bulkCreate(WorkOrdersData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateHumanResourceWithOrganization(),
await associateInventoryWithOrganization(),
await associateMachineryWithOrganization(),
await associateQualityControlWithWork_order(),
await associateQualityControlWithOrganization(),
// Similar logic for "relation_many"
await associateRawMaterialWithOrganization(),
await associateSupplierWithOrganization(),
await associateWorkOrderWithProduction_manager(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateWorkOrderWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('human_resources', null, {});
await queryInterface.bulkDelete('inventory', null, {});
await queryInterface.bulkDelete('machinery', null, {});
await queryInterface.bulkDelete('quality_control', null, {});
await queryInterface.bulkDelete('raw_materials', null, {});
await queryInterface.bulkDelete('suppliers', null, {});
await queryInterface.bulkDelete('work_orders', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};