const db = require('../models'); const Users = db.users; const Bottles = db.bottles; const Brands = db.brands; const Distilleries = db.distilleries; const BottlesData = [ { name: 'Old Forester 1920', // type code here for "relation_one" field proof: 115, type: 'Rye', notes: 'Rich and full-bodied', tasting_notes: 'Caramel, vanilla, and oak', msrp_range: '$60-$70', secondary_value_range: '$80-$100', opened_bottle_indicator: false, quantity: 1, barcode: '123456789012', // type code here for "images" field age: 4, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Lagavulin 16', // type code here for "relation_one" field proof: 86, type: 'Bourbon', notes: 'Peaty and smoky', tasting_notes: 'Smoke, seaweed, and vanilla', msrp_range: '$100-$120', secondary_value_range: '$150-$180', opened_bottle_indicator: true, quantity: 1, barcode: '234567890123', // type code here for "images" field age: 16, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Buffalo Trace', // type code here for "relation_one" field proof: 90, type: 'Bourbon', notes: 'Smooth and balanced', tasting_notes: 'Vanilla, caramel, and spice', msrp_range: '$25-$35', secondary_value_range: '$40-$50', opened_bottle_indicator: false, quantity: 2, barcode: '345678901234', // type code here for "images" field age: 8, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Redbreast 12', // type code here for "relation_one" field proof: 80, type: 'Rye', notes: 'Rich and complex', tasting_notes: 'Sherry, fruit, and spice', msrp_range: '$50-$60', secondary_value_range: '$70-$90', opened_bottle_indicator: true, quantity: 1, barcode: '456789012345', // type code here for "images" field age: 12, // type code here for "relation_one" field // type code here for "relation_one" field }, { name: 'Pappy Van Winkle 15', // type code here for "relation_one" field proof: 107, type: 'Bourbon', notes: 'Rare and exquisite', tasting_notes: 'Vanilla, oak, and spice', msrp_range: '$120-$150', secondary_value_range: '$2000-$2500', opened_bottle_indicator: true, quantity: 1, barcode: '567890123456', // type code here for "images" field age: 15, // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const BrandsData = [ { name: 'Old Forester', // type code here for "relation_one" field }, { name: 'Lagavulin', // type code here for "relation_one" field }, { name: 'Buffalo Trace', // type code here for "relation_one" field }, { name: 'Redbreast', // type code here for "relation_one" field }, { name: 'Pappy Van Winkle', // type code here for "relation_one" field }, ]; const DistilleriesData = [ { name: 'Old Forester', }, { name: 'Lagavulin', }, { name: 'Buffalo Trace', }, { name: 'Midleton', }, { name: 'Old Rip Van Winkle', }, ]; // Similar logic for "relation_many" async function associateBottleWithBrand() { const relatedBrand0 = await Brands.findOne({ offset: Math.floor(Math.random() * (await Brands.count())), }); const Bottle0 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Bottle0?.setBrand) { await Bottle0.setBrand(relatedBrand0); } const relatedBrand1 = await Brands.findOne({ offset: Math.floor(Math.random() * (await Brands.count())), }); const Bottle1 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Bottle1?.setBrand) { await Bottle1.setBrand(relatedBrand1); } const relatedBrand2 = await Brands.findOne({ offset: Math.floor(Math.random() * (await Brands.count())), }); const Bottle2 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Bottle2?.setBrand) { await Bottle2.setBrand(relatedBrand2); } const relatedBrand3 = await Brands.findOne({ offset: Math.floor(Math.random() * (await Brands.count())), }); const Bottle3 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Bottle3?.setBrand) { await Bottle3.setBrand(relatedBrand3); } const relatedBrand4 = await Brands.findOne({ offset: Math.floor(Math.random() * (await Brands.count())), }); const Bottle4 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Bottle4?.setBrand) { await Bottle4.setBrand(relatedBrand4); } } async function associateBottleWithDistillery() { const relatedDistillery0 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Bottle0 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Bottle0?.setDistillery) { await Bottle0.setDistillery(relatedDistillery0); } const relatedDistillery1 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Bottle1 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Bottle1?.setDistillery) { await Bottle1.setDistillery(relatedDistillery1); } const relatedDistillery2 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Bottle2 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Bottle2?.setDistillery) { await Bottle2.setDistillery(relatedDistillery2); } const relatedDistillery3 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Bottle3 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Bottle3?.setDistillery) { await Bottle3.setDistillery(relatedDistillery3); } const relatedDistillery4 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Bottle4 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Bottle4?.setDistillery) { await Bottle4.setDistillery(relatedDistillery4); } } async function associateBottleWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bottle0 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Bottle0?.setUser) { await Bottle0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bottle1 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Bottle1?.setUser) { await Bottle1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bottle2 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Bottle2?.setUser) { await Bottle2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bottle3 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Bottle3?.setUser) { await Bottle3.setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Bottle4 = await Bottles.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Bottle4?.setUser) { await Bottle4.setUser(relatedUser4); } } async function associateBrandWithDistillery() { const relatedDistillery0 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Brand0 = await Brands.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Brand0?.setDistillery) { await Brand0.setDistillery(relatedDistillery0); } const relatedDistillery1 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Brand1 = await Brands.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Brand1?.setDistillery) { await Brand1.setDistillery(relatedDistillery1); } const relatedDistillery2 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Brand2 = await Brands.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Brand2?.setDistillery) { await Brand2.setDistillery(relatedDistillery2); } const relatedDistillery3 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Brand3 = await Brands.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Brand3?.setDistillery) { await Brand3.setDistillery(relatedDistillery3); } const relatedDistillery4 = await Distilleries.findOne({ offset: Math.floor(Math.random() * (await Distilleries.count())), }); const Brand4 = await Brands.findOne({ order: [['id', 'ASC']], offset: 4, }); if (Brand4?.setDistillery) { await Brand4.setDistillery(relatedDistillery4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Bottles.bulkCreate(BottlesData); await Brands.bulkCreate(BrandsData); await Distilleries.bulkCreate(DistilleriesData); await Promise.all([ // Similar logic for "relation_many" await associateBottleWithBrand(), await associateBottleWithDistillery(), await associateBottleWithUser(), await associateBrandWithDistillery(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('bottles', null, {}); await queryInterface.bulkDelete('brands', null, {}); await queryInterface.bulkDelete('distilleries', null, {}); }, };