280 lines
5.7 KiB
JavaScript
280 lines
5.7 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Carts = db.carts;
|
|
|
|
const Designs = db.designs;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Stones = db.stones;
|
|
|
|
const CartsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
last_updated: new Date('2023-10-01T15:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
last_updated: new Date('2023-10-02T16:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
last_updated: new Date('2023-10-03T17:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const DesignsData = [
|
|
{
|
|
name: 'Elegant Ring',
|
|
|
|
description: 'A beautifully crafted ring with intricate designs.',
|
|
|
|
category: 'Mangalsutra',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Classic Necklace',
|
|
|
|
description: 'A timeless necklace design with a modern twist.',
|
|
|
|
category: 'Rings',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "images" field
|
|
},
|
|
|
|
{
|
|
name: 'Stylish Bracelet',
|
|
|
|
description: 'A trendy bracelet that complements any outfit.',
|
|
|
|
category: 'Necklace',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "images" field
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
status: 'Pending',
|
|
|
|
total_price: 650,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
status: 'InProduction',
|
|
|
|
total_price: 700,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
order_date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
|
|
total_price: 300,
|
|
},
|
|
];
|
|
|
|
const StonesData = [
|
|
{
|
|
name: 'Ruby',
|
|
|
|
price: 150,
|
|
},
|
|
|
|
{
|
|
name: 'Emerald',
|
|
|
|
price: 200,
|
|
},
|
|
|
|
{
|
|
name: 'Sapphire',
|
|
|
|
price: 250,
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCartWithCustomer() {
|
|
const relatedCustomer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Cart0 = await Carts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Cart0?.setCustomer) {
|
|
await Cart0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Cart1 = await Carts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Cart1?.setCustomer) {
|
|
await Cart1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Cart2 = await Carts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Cart2?.setCustomer) {
|
|
await Cart2.setCustomer(relatedCustomer2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateOrderWithCustomer() {
|
|
const relatedCustomer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setCustomer) {
|
|
await Order0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setCustomer) {
|
|
await Order1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setCustomer) {
|
|
await Order2.setCustomer(relatedCustomer2);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithDesign() {
|
|
const relatedDesign0 = await Designs.findOne({
|
|
offset: Math.floor(Math.random() * (await Designs.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setDesign) {
|
|
await Order0.setDesign(relatedDesign0);
|
|
}
|
|
|
|
const relatedDesign1 = await Designs.findOne({
|
|
offset: Math.floor(Math.random() * (await Designs.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setDesign) {
|
|
await Order1.setDesign(relatedDesign1);
|
|
}
|
|
|
|
const relatedDesign2 = await Designs.findOne({
|
|
offset: Math.floor(Math.random() * (await Designs.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setDesign) {
|
|
await Order2.setDesign(relatedDesign2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Carts.bulkCreate(CartsData);
|
|
|
|
await Designs.bulkCreate(DesignsData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Stones.bulkCreate(StonesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCartWithCustomer(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateOrderWithCustomer(),
|
|
|
|
await associateOrderWithDesign(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('carts', null, {});
|
|
|
|
await queryInterface.bulkDelete('designs', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('stones', null, {});
|
|
},
|
|
};
|