33243/backend/src/db/seeders/20231127130745-sample-data.js
2025-08-06 14:21:13 +00:00

773 lines
19 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Attendees = db.attendees;
const Events = db.events;
const Products = db.products;
const Vendors = db.vendors;
const Organizations = db.organizations;
const AttendeesData = [
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const EventsData = [
{
title: 'Annual Gala',
start_date: new Date('2023-12-01T18:00:00Z'),
end_date: new Date('2023-12-01T23:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Tech Conference 2023',
start_date: new Date('2023-11-15T09:00:00Z'),
end_date: new Date('2023-11-17T17:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Wedding Expo',
start_date: new Date('2023-10-20T10:00:00Z'),
end_date: new Date('2023-10-20T18:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Music Festival',
start_date: new Date('2023-09-05T12:00:00Z'),
end_date: new Date('2023-09-07T23:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
title: 'Art Fair',
start_date: new Date('2023-08-12T10:00:00Z'),
end_date: new Date('2023-08-12T20:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ProductsData = [
{
name: 'Premium Sound System',
price: 1500,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Gourmet Catering Package',
price: 2500,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Elegant Venue Rental',
price: 5000,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Luxury Floral Arrangement',
price: 300,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
name: 'Event Lighting Package',
price: 1200,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const VendorsData = [
{
name: 'Event Supplies Co.',
description: 'Leading supplier of event materials and decorations.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Catering Masters',
description: 'Top-notch catering services for all event types.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Sound & Light Pros',
description: 'Professional sound and lighting solutions.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Venue Rentals Inc.',
description: 'Exclusive venue rental services for events.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Floral Designs',
description: 'Beautiful floral arrangements for any occasion.',
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Richard Feynman',
},
{
name: 'Emil Fischer',
},
{
name: 'Dmitri Mendeleev',
},
{
name: 'Wilhelm Wundt',
},
{
name: 'Christiaan Huygens',
},
];
// 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);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setOrganization) {
await User4.setOrganization(relatedOrganization4);
}
}
async function associateAttendeeWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendee0 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Attendee0?.setUser) {
await Attendee0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendee1 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Attendee1?.setUser) {
await Attendee1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendee2 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Attendee2?.setUser) {
await Attendee2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendee3 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Attendee3?.setUser) {
await Attendee3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attendee4 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Attendee4?.setUser) {
await Attendee4.setUser(relatedUser4);
}
}
// Similar logic for "relation_many"
async function associateAttendeeWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attendee0 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Attendee0?.setOrganization) {
await Attendee0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attendee1 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Attendee1?.setOrganization) {
await Attendee1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attendee2 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Attendee2?.setOrganization) {
await Attendee2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attendee3 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Attendee3?.setOrganization) {
await Attendee3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Attendee4 = await Attendees.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Attendee4?.setOrganization) {
await Attendee4.setOrganization(relatedOrganization4);
}
}
// Similar logic for "relation_many"
async function associateEventWithVendor() {
const relatedVendor0 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Event0 = await Events.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Event0?.setVendor) {
await Event0.setVendor(relatedVendor0);
}
const relatedVendor1 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Event1 = await Events.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Event1?.setVendor) {
await Event1.setVendor(relatedVendor1);
}
const relatedVendor2 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Event2 = await Events.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Event2?.setVendor) {
await Event2.setVendor(relatedVendor2);
}
const relatedVendor3 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Event3 = await Events.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Event3?.setVendor) {
await Event3.setVendor(relatedVendor3);
}
const relatedVendor4 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Event4 = await Events.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Event4?.setVendor) {
await Event4.setVendor(relatedVendor4);
}
}
async function associateEventWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Event0 = await Events.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Event0?.setOrganization) {
await Event0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Event1 = await Events.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Event1?.setOrganization) {
await Event1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Event2 = await Events.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Event2?.setOrganization) {
await Event2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Event3 = await Events.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Event3?.setOrganization) {
await Event3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Event4 = await Events.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Event4?.setOrganization) {
await Event4.setOrganization(relatedOrganization4);
}
}
async function associateProductWithVendor() {
const relatedVendor0 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Product0 = await Products.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Product0?.setVendor) {
await Product0.setVendor(relatedVendor0);
}
const relatedVendor1 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Product1 = await Products.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Product1?.setVendor) {
await Product1.setVendor(relatedVendor1);
}
const relatedVendor2 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Product2 = await Products.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Product2?.setVendor) {
await Product2.setVendor(relatedVendor2);
}
const relatedVendor3 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Product3 = await Products.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Product3?.setVendor) {
await Product3.setVendor(relatedVendor3);
}
const relatedVendor4 = await Vendors.findOne({
offset: Math.floor(Math.random() * (await Vendors.count())),
});
const Product4 = await Products.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Product4?.setVendor) {
await Product4.setVendor(relatedVendor4);
}
}
async function associateProductWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product0 = await Products.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Product0?.setOrganization) {
await Product0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product1 = await Products.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Product1?.setOrganization) {
await Product1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product2 = await Products.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Product2?.setOrganization) {
await Product2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product3 = await Products.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Product3?.setOrganization) {
await Product3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Product4 = await Products.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Product4?.setOrganization) {
await Product4.setOrganization(relatedOrganization4);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateVendorWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Vendor0 = await Vendors.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Vendor0?.setOrganization) {
await Vendor0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Vendor1 = await Vendors.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Vendor1?.setOrganization) {
await Vendor1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Vendor2 = await Vendors.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Vendor2?.setOrganization) {
await Vendor2.setOrganization(relatedOrganization2);
}
const relatedOrganization3 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Vendor3 = await Vendors.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Vendor3?.setOrganization) {
await Vendor3.setOrganization(relatedOrganization3);
}
const relatedOrganization4 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Vendor4 = await Vendors.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Vendor4?.setOrganization) {
await Vendor4.setOrganization(relatedOrganization4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Attendees.bulkCreate(AttendeesData);
await Events.bulkCreate(EventsData);
await Products.bulkCreate(ProductsData);
await Vendors.bulkCreate(VendorsData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateAttendeeWithUser(),
// Similar logic for "relation_many"
await associateAttendeeWithOrganization(),
// Similar logic for "relation_many"
await associateEventWithVendor(),
await associateEventWithOrganization(),
await associateProductWithVendor(),
await associateProductWithOrganization(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateVendorWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('attendees', null, {});
await queryInterface.bulkDelete('events', null, {});
await queryInterface.bulkDelete('products', null, {});
await queryInterface.bulkDelete('vendors', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};