234 lines
4.9 KiB
JavaScript
234 lines
4.9 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Ads = db.ads;
|
|
|
|
const Clicks = db.clicks;
|
|
|
|
const Withdrawals = db.withdrawals;
|
|
|
|
const AdsData = [
|
|
{
|
|
title: 'Ad Campaign 1',
|
|
|
|
description: 'Promote our new product line.',
|
|
|
|
start_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-31T23:59:59Z'),
|
|
},
|
|
|
|
{
|
|
title: 'Ad Campaign 2',
|
|
|
|
description: 'Special discount offer.',
|
|
|
|
start_date: new Date('2023-10-05T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-20T23:59:59Z'),
|
|
},
|
|
|
|
{
|
|
title: 'Ad Campaign 3',
|
|
|
|
description: 'Join our newsletter for updates.',
|
|
|
|
start_date: new Date('2023-10-10T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-25T23:59:59Z'),
|
|
},
|
|
];
|
|
|
|
const ClicksData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
click_time: new Date('2023-10-01T10:10:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
click_time: new Date('2023-10-02T11:40:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
click_time: new Date('2023-10-03T09:55:00Z'),
|
|
},
|
|
];
|
|
|
|
const WithdrawalsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 15000,
|
|
|
|
withdrawal_date: new Date('2023-10-06T10:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 20000,
|
|
|
|
withdrawal_date: new Date('2023-10-07T11:30:00Z'),
|
|
|
|
status: 'Failed',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
amount: 25000,
|
|
|
|
withdrawal_date: new Date('2023-10-08T09:45:00Z'),
|
|
|
|
status: 'Pending',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateClickWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Click0 = await Clicks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Click0?.setUser) {
|
|
await Click0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Click1 = await Clicks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Click1?.setUser) {
|
|
await Click1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Click2 = await Clicks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Click2?.setUser) {
|
|
await Click2.setUser(relatedUser2);
|
|
}
|
|
}
|
|
|
|
async function associateClickWithAd() {
|
|
const relatedAd0 = await Ads.findOne({
|
|
offset: Math.floor(Math.random() * (await Ads.count())),
|
|
});
|
|
const Click0 = await Clicks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Click0?.setAd) {
|
|
await Click0.setAd(relatedAd0);
|
|
}
|
|
|
|
const relatedAd1 = await Ads.findOne({
|
|
offset: Math.floor(Math.random() * (await Ads.count())),
|
|
});
|
|
const Click1 = await Clicks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Click1?.setAd) {
|
|
await Click1.setAd(relatedAd1);
|
|
}
|
|
|
|
const relatedAd2 = await Ads.findOne({
|
|
offset: Math.floor(Math.random() * (await Ads.count())),
|
|
});
|
|
const Click2 = await Clicks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Click2?.setAd) {
|
|
await Click2.setAd(relatedAd2);
|
|
}
|
|
}
|
|
|
|
async function associateWithdrawalWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Withdrawal0 = await Withdrawals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Withdrawal0?.setUser) {
|
|
await Withdrawal0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Withdrawal1 = await Withdrawals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Withdrawal1?.setUser) {
|
|
await Withdrawal1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Withdrawal2 = await Withdrawals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Withdrawal2?.setUser) {
|
|
await Withdrawal2.setUser(relatedUser2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Ads.bulkCreate(AdsData);
|
|
|
|
await Clicks.bulkCreate(ClicksData);
|
|
|
|
await Withdrawals.bulkCreate(WithdrawalsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateClickWithUser(),
|
|
|
|
await associateClickWithAd(),
|
|
|
|
await associateWithdrawalWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('ads', null, {});
|
|
|
|
await queryInterface.bulkDelete('clicks', null, {});
|
|
|
|
await queryInterface.bulkDelete('withdrawals', null, {});
|
|
},
|
|
};
|