236 lines
4.7 KiB
JavaScript
236 lines
4.7 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Brands = db.brands;
|
|
|
|
const Features = db.features;
|
|
|
|
const Products = db.products;
|
|
|
|
const BrandsData = [
|
|
{
|
|
name: 'Hydro Flask',
|
|
|
|
description: 'High-quality insulated bottles and tumblers.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Yeti',
|
|
|
|
description: 'Durable and stylish drinkware for outdoor enthusiasts.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Contigo',
|
|
|
|
description: 'Innovative and spill-proof cups and mugs.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Nalgene',
|
|
|
|
description: 'Reliable and versatile water bottles.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'CamelBak',
|
|
|
|
description: 'Hydration solutions for active lifestyles.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const FeaturesData = [
|
|
{
|
|
name: 'Material',
|
|
|
|
value: 'Stainless Steel',
|
|
},
|
|
|
|
{
|
|
name: 'Capacity',
|
|
|
|
value: '32 oz',
|
|
},
|
|
|
|
{
|
|
name: 'Insulation',
|
|
|
|
value: 'Double Wall Vacuum',
|
|
},
|
|
|
|
{
|
|
name: 'Color',
|
|
|
|
value: 'Black',
|
|
},
|
|
|
|
{
|
|
name: 'Lid Type',
|
|
|
|
value: 'Screw Cap',
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Hydro Flask 32 oz',
|
|
|
|
description: 'Insulated stainless steel water bottle.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
affiliate_link: 'https://amazon.com/hydroflask32oz',
|
|
},
|
|
|
|
{
|
|
name: 'Yeti Rambler 20 oz',
|
|
|
|
description: 'Durable stainless steel tumbler.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
affiliate_link: 'https://amazon.com/yetirambler20oz',
|
|
},
|
|
|
|
{
|
|
name: 'Contigo Autoseal West Loop',
|
|
|
|
description: 'Spill-proof travel mug with autoseal technology.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
affiliate_link: 'https://amazon.com/contigowestloop',
|
|
},
|
|
|
|
{
|
|
name: 'Nalgene Wide Mouth 32 oz',
|
|
|
|
description: 'Classic BPA-free water bottle.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
affiliate_link: 'https://amazon.com/nalgene32oz',
|
|
},
|
|
|
|
{
|
|
name: 'CamelBak Eddy+',
|
|
|
|
description: 'Leak-proof water bottle with straw.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
affiliate_link: 'https://amazon.com/camelbakeddyplus',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateProductWithBrand() {
|
|
const relatedBrand0 = await Brands.findOne({
|
|
offset: Math.floor(Math.random() * (await Brands.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setBrand) {
|
|
await Product0.setBrand(relatedBrand0);
|
|
}
|
|
|
|
const relatedBrand1 = await Brands.findOne({
|
|
offset: Math.floor(Math.random() * (await Brands.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setBrand) {
|
|
await Product1.setBrand(relatedBrand1);
|
|
}
|
|
|
|
const relatedBrand2 = await Brands.findOne({
|
|
offset: Math.floor(Math.random() * (await Brands.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setBrand) {
|
|
await Product2.setBrand(relatedBrand2);
|
|
}
|
|
|
|
const relatedBrand3 = await Brands.findOne({
|
|
offset: Math.floor(Math.random() * (await Brands.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setBrand) {
|
|
await Product3.setBrand(relatedBrand3);
|
|
}
|
|
|
|
const relatedBrand4 = await Brands.findOne({
|
|
offset: Math.floor(Math.random() * (await Brands.count())),
|
|
});
|
|
const Product4 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Product4?.setBrand) {
|
|
await Product4.setBrand(relatedBrand4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Brands.bulkCreate(BrandsData);
|
|
|
|
await Features.bulkCreate(FeaturesData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProductWithBrand(),
|
|
|
|
// Similar logic for "relation_many"
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('brands', null, {});
|
|
|
|
await queryInterface.bulkDelete('features', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
},
|
|
};
|