30011/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-18 17:10:28 +00:00

795 lines
19 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Categories = db.categories;
const CoffeeBlends = db.coffee_blends;
const Customers = db.customers;
const Orders = db.orders;
const Payments = db.payments;
const Reports = db.reports;
const CoffeeBusinesses = db.coffee_businesses;
const CategoriesData = [
{
name: 'Organic',
description: 'Grown without synthetic fertilizers or pesticides.',
// type code here for "relation_one" field
},
{
name: 'Fair Trade',
description: 'Ensures fair prices and ethical treatment for farmers.',
// type code here for "relation_one" field
},
{
name: 'Seasonal',
description: 'Available only during specific times of the year.',
// type code here for "relation_one" field
},
{
name: 'Decaf',
description: 'Caffeine-free coffee options.',
// type code here for "relation_one" field
},
];
const CoffeeBlendsData = [
{
name: 'Espresso Roast',
price: 12.99,
stock_level: 150,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Colombian Single Origin',
price: 14.99,
stock_level: 200,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Ethiopian Yirgacheffe',
price: 16.99,
stock_level: 100,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Sumatra Mandheling',
price: 15.49,
stock_level: 120,
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const CustomersData = [
{
first_name: 'John',
last_name: 'Doe',
email: 'john.doe@example.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Jane',
last_name: 'Smith',
email: 'jane.smith@example.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Emily',
last_name: 'Johnson',
email: 'emily.johnson@example.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Michael',
last_name: 'Brown',
email: 'michael.brown@example.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const OrdersData = [
{
order_date: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
status: 'Cancelled',
// type code here for "relation_one" field
},
{
order_date: new Date('2023-10-02T11:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
status: 'Shipped',
// type code here for "relation_one" field
},
{
order_date: new Date('2023-10-03T14:45:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
status: 'Delivered',
// type code here for "relation_one" field
},
{
order_date: new Date('2023-10-04T09:15:00Z'),
// type code here for "relation_one" field
// type code here for "relation_many" field
status: 'Pending',
// type code here for "relation_one" field
},
];
const PaymentsData = [
{
amount: 25.98,
payment_date: new Date('2023-10-01T10:05:00Z'),
// type code here for "relation_one" field
status: 'Completed',
// type code here for "relation_one" field
},
{
amount: 16.99,
payment_date: new Date('2023-10-02T11:35:00Z'),
// type code here for "relation_one" field
status: 'Completed',
// type code here for "relation_one" field
},
{
amount: 32.48,
payment_date: new Date('2023-10-03T14:50:00Z'),
// type code here for "relation_one" field
status: 'Pending',
// type code here for "relation_one" field
},
{
amount: 30.48,
payment_date: new Date('2023-10-04T09:20:00Z'),
// type code here for "relation_one" field
status: 'Failed',
// type code here for "relation_one" field
},
];
const ReportsData = [
{
generated_at: new Date('2023-10-01T12:00:00Z'),
report_type: 'Sales Report',
// type code here for "files" field
// type code here for "relation_one" field
},
{
generated_at: new Date('2023-10-02T12:00:00Z'),
report_type: 'Inventory Report',
// type code here for "files" field
// type code here for "relation_one" field
},
{
generated_at: new Date('2023-10-03T12:00:00Z'),
report_type: 'Customer Feedback',
// type code here for "files" field
// type code here for "relation_one" field
},
{
generated_at: new Date('2023-10-04T12:00:00Z'),
report_type: 'Monthly Summary',
// type code here for "files" field
// type code here for "relation_one" field
},
];
const CoffeeBusinessesData = [
{
name: 'Michael Faraday',
},
{
name: 'Ernest Rutherford',
},
{
name: 'J. Robert Oppenheimer',
},
{
name: 'Hans Bethe',
},
];
async function associateCategoryWithCoffee_business() {
const relatedCoffee_business0 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Category0 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Category0?.setCoffee_business) {
await Category0.setCoffee_business(relatedCoffee_business0);
}
const relatedCoffee_business1 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Category1 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Category1?.setCoffee_business) {
await Category1.setCoffee_business(relatedCoffee_business1);
}
const relatedCoffee_business2 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Category2 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Category2?.setCoffee_business) {
await Category2.setCoffee_business(relatedCoffee_business2);
}
const relatedCoffee_business3 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Category3 = await Categories.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Category3?.setCoffee_business) {
await Category3.setCoffee_business(relatedCoffee_business3);
}
}
// Similar logic for "relation_many"
async function associateUserWithCoffee_business() {
const relatedCoffee_business0 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setCoffee_business) {
await User0.setCoffee_business(relatedCoffee_business0);
}
const relatedCoffee_business1 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setCoffee_business) {
await User1.setCoffee_business(relatedCoffee_business1);
}
const relatedCoffee_business2 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setCoffee_business) {
await User2.setCoffee_business(relatedCoffee_business2);
}
const relatedCoffee_business3 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setCoffee_business) {
await User3.setCoffee_business(relatedCoffee_business3);
}
}
// Similar logic for "relation_many"
async function associateCoffeeBlendWithCoffee_business() {
const relatedCoffee_business0 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const CoffeeBlend0 = await CoffeeBlends.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (CoffeeBlend0?.setCoffee_business) {
await CoffeeBlend0.setCoffee_business(relatedCoffee_business0);
}
const relatedCoffee_business1 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const CoffeeBlend1 = await CoffeeBlends.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (CoffeeBlend1?.setCoffee_business) {
await CoffeeBlend1.setCoffee_business(relatedCoffee_business1);
}
const relatedCoffee_business2 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const CoffeeBlend2 = await CoffeeBlends.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (CoffeeBlend2?.setCoffee_business) {
await CoffeeBlend2.setCoffee_business(relatedCoffee_business2);
}
const relatedCoffee_business3 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const CoffeeBlend3 = await CoffeeBlends.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (CoffeeBlend3?.setCoffee_business) {
await CoffeeBlend3.setCoffee_business(relatedCoffee_business3);
}
}
// Similar logic for "relation_many"
async function associateCustomerWithCoffee_business() {
const relatedCoffee_business0 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Customer0 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Customer0?.setCoffee_business) {
await Customer0.setCoffee_business(relatedCoffee_business0);
}
const relatedCoffee_business1 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Customer1 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Customer1?.setCoffee_business) {
await Customer1.setCoffee_business(relatedCoffee_business1);
}
const relatedCoffee_business2 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Customer2 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Customer2?.setCoffee_business) {
await Customer2.setCoffee_business(relatedCoffee_business2);
}
const relatedCoffee_business3 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Customer3 = await Customers.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Customer3?.setCoffee_business) {
await Customer3.setCoffee_business(relatedCoffee_business3);
}
}
async function associateOrderWithCustomer() {
const relatedCustomer0 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Order0 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Order0?.setCustomer) {
await Order0.setCustomer(relatedCustomer0);
}
const relatedCustomer1 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Order1 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Order1?.setCustomer) {
await Order1.setCustomer(relatedCustomer1);
}
const relatedCustomer2 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Order2 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Order2?.setCustomer) {
await Order2.setCustomer(relatedCustomer2);
}
const relatedCustomer3 = await Customers.findOne({
offset: Math.floor(Math.random() * (await Customers.count())),
});
const Order3 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Order3?.setCustomer) {
await Order3.setCustomer(relatedCustomer3);
}
}
// Similar logic for "relation_many"
async function associateOrderWithCoffee_business() {
const relatedCoffee_business0 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Order0 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Order0?.setCoffee_business) {
await Order0.setCoffee_business(relatedCoffee_business0);
}
const relatedCoffee_business1 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Order1 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Order1?.setCoffee_business) {
await Order1.setCoffee_business(relatedCoffee_business1);
}
const relatedCoffee_business2 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Order2 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Order2?.setCoffee_business) {
await Order2.setCoffee_business(relatedCoffee_business2);
}
const relatedCoffee_business3 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Order3 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Order3?.setCoffee_business) {
await Order3.setCoffee_business(relatedCoffee_business3);
}
}
async function associatePaymentWithOrder() {
const relatedOrder0 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Payment0 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Payment0?.setOrder) {
await Payment0.setOrder(relatedOrder0);
}
const relatedOrder1 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Payment1 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Payment1?.setOrder) {
await Payment1.setOrder(relatedOrder1);
}
const relatedOrder2 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Payment2 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Payment2?.setOrder) {
await Payment2.setOrder(relatedOrder2);
}
const relatedOrder3 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const Payment3 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Payment3?.setOrder) {
await Payment3.setOrder(relatedOrder3);
}
}
async function associatePaymentWithCoffee_business() {
const relatedCoffee_business0 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Payment0 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Payment0?.setCoffee_business) {
await Payment0.setCoffee_business(relatedCoffee_business0);
}
const relatedCoffee_business1 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Payment1 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Payment1?.setCoffee_business) {
await Payment1.setCoffee_business(relatedCoffee_business1);
}
const relatedCoffee_business2 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Payment2 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Payment2?.setCoffee_business) {
await Payment2.setCoffee_business(relatedCoffee_business2);
}
const relatedCoffee_business3 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Payment3 = await Payments.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Payment3?.setCoffee_business) {
await Payment3.setCoffee_business(relatedCoffee_business3);
}
}
async function associateReportWithCoffee_business() {
const relatedCoffee_business0 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Report0 = await Reports.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Report0?.setCoffee_business) {
await Report0.setCoffee_business(relatedCoffee_business0);
}
const relatedCoffee_business1 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Report1 = await Reports.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Report1?.setCoffee_business) {
await Report1.setCoffee_business(relatedCoffee_business1);
}
const relatedCoffee_business2 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Report2 = await Reports.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Report2?.setCoffee_business) {
await Report2.setCoffee_business(relatedCoffee_business2);
}
const relatedCoffee_business3 = await CoffeeBusinesses.findOne({
offset: Math.floor(Math.random() * (await CoffeeBusinesses.count())),
});
const Report3 = await Reports.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Report3?.setCoffee_business) {
await Report3.setCoffee_business(relatedCoffee_business3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Categories.bulkCreate(CategoriesData);
await CoffeeBlends.bulkCreate(CoffeeBlendsData);
await Customers.bulkCreate(CustomersData);
await Orders.bulkCreate(OrdersData);
await Payments.bulkCreate(PaymentsData);
await Reports.bulkCreate(ReportsData);
await CoffeeBusinesses.bulkCreate(CoffeeBusinessesData);
await Promise.all([
await associateCategoryWithCoffee_business(),
// Similar logic for "relation_many"
await associateUserWithCoffee_business(),
// Similar logic for "relation_many"
await associateCoffeeBlendWithCoffee_business(),
// Similar logic for "relation_many"
await associateCustomerWithCoffee_business(),
await associateOrderWithCustomer(),
// Similar logic for "relation_many"
await associateOrderWithCoffee_business(),
await associatePaymentWithOrder(),
await associatePaymentWithCoffee_business(),
await associateReportWithCoffee_business(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('categories', null, {});
await queryInterface.bulkDelete('coffee_blends', null, {});
await queryInterface.bulkDelete('customers', null, {});
await queryInterface.bulkDelete('orders', null, {});
await queryInterface.bulkDelete('payments', null, {});
await queryInterface.bulkDelete('reports', null, {});
await queryInterface.bulkDelete('coffee_businesses', null, {});
},
};