375 lines
8.5 KiB
JavaScript
375 lines
8.5 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const MiningSessions = db.mining_sessions;
|
|
|
|
const ReinvestmentRules = db.reinvestment_rules;
|
|
|
|
const TransactionHistory = db.transaction_history;
|
|
|
|
const Withdrawals = db.withdrawals;
|
|
|
|
const MiningSessionsData = [
|
|
{
|
|
start_time: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-01T16:00:00Z'),
|
|
|
|
earnings: 12.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
start_time: new Date('2023-10-02T09:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-02T17:00:00Z'),
|
|
|
|
earnings: 15,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
start_time: new Date('2023-10-03T10:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-03T18:00:00Z'),
|
|
|
|
earnings: 14.2,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
start_time: new Date('2023-10-04T11:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-04T19:00:00Z'),
|
|
|
|
earnings: 16.8,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ReinvestmentRulesData = [
|
|
{
|
|
percentage: 10,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
percentage: 15,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
percentage: 20,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
percentage: 25,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TransactionHistoryData = [
|
|
{
|
|
transaction_time: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
transaction_type: 'mining',
|
|
|
|
amount: 12.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
transaction_time: new Date('2023-10-02T09:00:00Z'),
|
|
|
|
transaction_type: 'mining',
|
|
|
|
amount: 1.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
transaction_time: new Date('2023-10-03T10:00:00Z'),
|
|
|
|
transaction_type: 'withdrawal',
|
|
|
|
amount: 5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
transaction_time: new Date('2023-10-04T11:00:00Z'),
|
|
|
|
transaction_type: 'reinvestment',
|
|
|
|
amount: 16.8,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const WithdrawalsData = [
|
|
{
|
|
withdrawal_time: new Date('2023-10-01T18:00:00Z'),
|
|
|
|
amount: 5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
withdrawal_time: new Date('2023-10-02T19:00:00Z'),
|
|
|
|
amount: 7.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
withdrawal_time: new Date('2023-10-03T20:00:00Z'),
|
|
|
|
amount: 6,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
withdrawal_time: new Date('2023-10-04T21:00:00Z'),
|
|
|
|
amount: 8.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateMiningSessionWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const MiningSession0 = await MiningSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (MiningSession0?.setUser) {
|
|
await MiningSession0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const MiningSession1 = await MiningSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (MiningSession1?.setUser) {
|
|
await MiningSession1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const MiningSession2 = await MiningSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (MiningSession2?.setUser) {
|
|
await MiningSession2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const MiningSession3 = await MiningSessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (MiningSession3?.setUser) {
|
|
await MiningSession3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associateReinvestmentRuleWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ReinvestmentRule0 = await ReinvestmentRules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ReinvestmentRule0?.setUser) {
|
|
await ReinvestmentRule0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ReinvestmentRule1 = await ReinvestmentRules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ReinvestmentRule1?.setUser) {
|
|
await ReinvestmentRule1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ReinvestmentRule2 = await ReinvestmentRules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ReinvestmentRule2?.setUser) {
|
|
await ReinvestmentRule2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ReinvestmentRule3 = await ReinvestmentRules.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ReinvestmentRule3?.setUser) {
|
|
await ReinvestmentRule3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associateTransactionHistoryWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const TransactionHistory0 = await TransactionHistory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (TransactionHistory0?.setUser) {
|
|
await TransactionHistory0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const TransactionHistory1 = await TransactionHistory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (TransactionHistory1?.setUser) {
|
|
await TransactionHistory1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const TransactionHistory2 = await TransactionHistory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (TransactionHistory2?.setUser) {
|
|
await TransactionHistory2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const TransactionHistory3 = await TransactionHistory.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (TransactionHistory3?.setUser) {
|
|
await TransactionHistory3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Withdrawal3 = await Withdrawals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Withdrawal3?.setUser) {
|
|
await Withdrawal3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await MiningSessions.bulkCreate(MiningSessionsData);
|
|
|
|
await ReinvestmentRules.bulkCreate(ReinvestmentRulesData);
|
|
|
|
await TransactionHistory.bulkCreate(TransactionHistoryData);
|
|
|
|
await Withdrawals.bulkCreate(WithdrawalsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateMiningSessionWithUser(),
|
|
|
|
await associateReinvestmentRuleWithUser(),
|
|
|
|
await associateTransactionHistoryWithUser(),
|
|
|
|
await associateWithdrawalWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('mining_sessions', null, {});
|
|
|
|
await queryInterface.bulkDelete('reinvestment_rules', null, {});
|
|
|
|
await queryInterface.bulkDelete('transaction_history', null, {});
|
|
|
|
await queryInterface.bulkDelete('withdrawals', null, {});
|
|
},
|
|
};
|