const db = require('../models'); const Users = db.users; const Admins = db.admins; const Participations = db.participations; const Sweepstakes = db.sweepstakes; const AdminsData = [ { admin_id: '6769704346', admin_tag: '@plane_tg', }, { admin_id: 'Nicolaus Copernicus', admin_tag: 'August Kekule', }, { admin_id: 'Werner Heisenberg', admin_tag: 'Edwin Hubble', }, ]; const ParticipationsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field status: 'lost', participation_date: new Date('2023-10-01T11:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field status: 'lost', participation_date: new Date('2023-10-02T15:00:00Z'), }, { // type code here for "relation_one" field // type code here for "relation_one" field status: 'won', participation_date: new Date('2023-10-03T10:00:00Z'), }, ]; const SweepstakesData = [ { name: 'NFT Brick Drawing', prize_count: 3, start_time: new Date('2023-10-01T10:00:00Z'), end_time: new Date('2023-10-01T12:00:00Z'), captcha_enabled: true, mandatory_subscription: true, country_lock: true, premium_only: true, // type code here for "relation_many" field }, { name: 'Crypto Coin Giveaway', prize_count: 5, start_time: new Date('2023-10-02T14:00:00Z'), end_time: new Date('2023-10-02T16:00:00Z'), captcha_enabled: true, mandatory_subscription: true, country_lock: true, premium_only: true, // type code here for "relation_many" field }, { name: 'Digital Art Raffle', prize_count: 2, start_time: new Date('2023-10-03T09:00:00Z'), end_time: new Date('2023-10-03T11:00:00Z'), captcha_enabled: true, mandatory_subscription: true, country_lock: false, premium_only: false, // type code here for "relation_many" field }, ]; // Similar logic for "relation_many" async function associateParticipationWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Participation0 = await Participations.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Participation0?.setUser) { await Participation0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Participation1 = await Participations.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Participation1?.setUser) { await Participation1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Participation2 = await Participations.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Participation2?.setUser) { await Participation2.setUser(relatedUser2); } } async function associateParticipationWithSweepstake() { const relatedSweepstake0 = await Sweepstakes.findOne({ offset: Math.floor(Math.random() * (await Sweepstakes.count())), }); const Participation0 = await Participations.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Participation0?.setSweepstake) { await Participation0.setSweepstake(relatedSweepstake0); } const relatedSweepstake1 = await Sweepstakes.findOne({ offset: Math.floor(Math.random() * (await Sweepstakes.count())), }); const Participation1 = await Participations.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Participation1?.setSweepstake) { await Participation1.setSweepstake(relatedSweepstake1); } const relatedSweepstake2 = await Sweepstakes.findOne({ offset: Math.floor(Math.random() * (await Sweepstakes.count())), }); const Participation2 = await Participations.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Participation2?.setSweepstake) { await Participation2.setSweepstake(relatedSweepstake2); } } // Similar logic for "relation_many" module.exports = { up: async (queryInterface, Sequelize) => { await Admins.bulkCreate(AdminsData); await Participations.bulkCreate(ParticipationsData); await Sweepstakes.bulkCreate(SweepstakesData); await Promise.all([ // Similar logic for "relation_many" await associateParticipationWithUser(), await associateParticipationWithSweepstake(), // Similar logic for "relation_many" ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('admins', null, {}); await queryInterface.bulkDelete('participations', null, {}); await queryInterface.bulkDelete('sweepstakes', null, {}); }, };