const db = require('../models'); const Users = db.users; const Files = db.files; const Transactions = db.transactions; const Wallets = db.wallets; const FilesData = [ { file_name: 'deposit_screenshot_1.png', file_url: 'https://example.com/files/deposit_screenshot_1.png', }, { file_name: 'withdrawal_screenshot_2.png', file_url: 'https://example.com/files/withdrawal_screenshot_2.png', }, { file_name: 'transfer_screenshot_3.png', file_url: 'https://example.com/files/transfer_screenshot_3.png', }, { file_name: 'deposit_screenshot_4.png', file_url: 'https://example.com/files/deposit_screenshot_4.png', }, ]; const TransactionsData = [ { // type code here for "relation_one" field type: 'withdrawal', amount: 100.5, status: 'approved', // type code here for "relation_one" field }, { // type code here for "relation_one" field type: 'transfer', amount: 50, status: 'approved', // type code here for "relation_one" field }, { // type code here for "relation_one" field type: 'transfer', amount: 75.25, status: 'rejected', // type code here for "relation_one" field }, { // type code here for "relation_one" field type: 'withdrawal', amount: 200, status: 'approved', // type code here for "relation_one" field }, ]; const WalletsData = [ { // type code here for "relation_one" field e_wallet_balance: 500, gaming_wallet_balance: 150, }, { // type code here for "relation_one" field e_wallet_balance: 300, gaming_wallet_balance: 200, }, { // type code here for "relation_one" field e_wallet_balance: 250, gaming_wallet_balance: 100, }, { // type code here for "relation_one" field e_wallet_balance: 400, gaming_wallet_balance: 50, }, ]; // Similar logic for "relation_many" async function associateTransactionWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction0 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Transaction0?.setUser) { await Transaction0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction1 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Transaction1?.setUser) { await Transaction1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction2 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Transaction2?.setUser) { await Transaction2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Transaction3 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Transaction3?.setUser) { await Transaction3.setUser(relatedUser3); } } async function associateTransactionWithScreenshot() { const relatedScreenshot0 = await Files.findOne({ offset: Math.floor(Math.random() * (await Files.count())), }); const Transaction0 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Transaction0?.setScreenshot) { await Transaction0.setScreenshot(relatedScreenshot0); } const relatedScreenshot1 = await Files.findOne({ offset: Math.floor(Math.random() * (await Files.count())), }); const Transaction1 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Transaction1?.setScreenshot) { await Transaction1.setScreenshot(relatedScreenshot1); } const relatedScreenshot2 = await Files.findOne({ offset: Math.floor(Math.random() * (await Files.count())), }); const Transaction2 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Transaction2?.setScreenshot) { await Transaction2.setScreenshot(relatedScreenshot2); } const relatedScreenshot3 = await Files.findOne({ offset: Math.floor(Math.random() * (await Files.count())), }); const Transaction3 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Transaction3?.setScreenshot) { await Transaction3.setScreenshot(relatedScreenshot3); } } async function associateWalletWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wallet0 = await Wallets.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Wallet0?.setUser) { await Wallet0.setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wallet1 = await Wallets.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Wallet1?.setUser) { await Wallet1.setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wallet2 = await Wallets.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Wallet2?.setUser) { await Wallet2.setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Wallet3 = await Wallets.findOne({ order: [['id', 'ASC']], offset: 3, }); if (Wallet3?.setUser) { await Wallet3.setUser(relatedUser3); } } module.exports = { up: async (queryInterface, Sequelize) => { await Files.bulkCreate(FilesData); await Transactions.bulkCreate(TransactionsData); await Wallets.bulkCreate(WalletsData); await Promise.all([ // Similar logic for "relation_many" await associateTransactionWithUser(), await associateTransactionWithScreenshot(), await associateWalletWithUser(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('files', null, {}); await queryInterface.bulkDelete('transactions', null, {}); await queryInterface.bulkDelete('wallets', null, {}); }, };