435 lines
9.0 KiB
JavaScript
435 lines
9.0 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Chats = db.chats;
|
|
|
|
const Bets = db.bets;
|
|
|
|
const Games = db.games;
|
|
|
|
const Leaderboards = db.leaderboards;
|
|
|
|
const ChatsData = [
|
|
{
|
|
message: 'Good luck everyone!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'This is exciting!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: "Can't wait to win big!",
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: "Let's do this!",
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const BetsData = [
|
|
{
|
|
amount: 100,
|
|
|
|
cash_out_multiplier: 1.5,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 200,
|
|
|
|
cash_out_multiplier: 2,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 150,
|
|
|
|
cash_out_multiplier: 1.8,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 250,
|
|
|
|
cash_out_multiplier: 2.5,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const GamesData = [
|
|
{
|
|
start_time: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-01T10:05:00Z'),
|
|
|
|
multiplier: 1.5,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
start_time: new Date('2023-10-01T11:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-01T11:05:00Z'),
|
|
|
|
multiplier: 2,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
start_time: new Date('2023-10-01T12:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-01T12:05:00Z'),
|
|
|
|
multiplier: 1.8,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
start_time: new Date('2023-10-01T13:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-01T13:05:00Z'),
|
|
|
|
multiplier: 2.5,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const LeaderboardsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 1,
|
|
|
|
total_winnings: 5000,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 2,
|
|
|
|
total_winnings: 4500,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 3,
|
|
|
|
total_winnings: 3000,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
rank: 4,
|
|
|
|
total_winnings: 2500,
|
|
},
|
|
];
|
|
|
|
async function associateChatWithPlayer() {
|
|
const relatedPlayer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat0 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Chat0?.setPlayer) {
|
|
await Chat0.setPlayer(relatedPlayer0);
|
|
}
|
|
|
|
const relatedPlayer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat1 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Chat1?.setPlayer) {
|
|
await Chat1.setPlayer(relatedPlayer1);
|
|
}
|
|
|
|
const relatedPlayer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat2 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Chat2?.setPlayer) {
|
|
await Chat2.setPlayer(relatedPlayer2);
|
|
}
|
|
|
|
const relatedPlayer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat3 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Chat3?.setPlayer) {
|
|
await Chat3.setPlayer(relatedPlayer3);
|
|
}
|
|
}
|
|
|
|
async function associateChatWithGame() {
|
|
const relatedGame0 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Chat0 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Chat0?.setGame) {
|
|
await Chat0.setGame(relatedGame0);
|
|
}
|
|
|
|
const relatedGame1 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Chat1 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Chat1?.setGame) {
|
|
await Chat1.setGame(relatedGame1);
|
|
}
|
|
|
|
const relatedGame2 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Chat2 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Chat2?.setGame) {
|
|
await Chat2.setGame(relatedGame2);
|
|
}
|
|
|
|
const relatedGame3 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Chat3 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Chat3?.setGame) {
|
|
await Chat3.setGame(relatedGame3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateBetWithPlayer() {
|
|
const relatedPlayer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Bet0 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Bet0?.setPlayer) {
|
|
await Bet0.setPlayer(relatedPlayer0);
|
|
}
|
|
|
|
const relatedPlayer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Bet1 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Bet1?.setPlayer) {
|
|
await Bet1.setPlayer(relatedPlayer1);
|
|
}
|
|
|
|
const relatedPlayer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Bet2 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Bet2?.setPlayer) {
|
|
await Bet2.setPlayer(relatedPlayer2);
|
|
}
|
|
|
|
const relatedPlayer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Bet3 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Bet3?.setPlayer) {
|
|
await Bet3.setPlayer(relatedPlayer3);
|
|
}
|
|
}
|
|
|
|
async function associateBetWithGame() {
|
|
const relatedGame0 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Bet0 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Bet0?.setGame) {
|
|
await Bet0.setGame(relatedGame0);
|
|
}
|
|
|
|
const relatedGame1 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Bet1 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Bet1?.setGame) {
|
|
await Bet1.setGame(relatedGame1);
|
|
}
|
|
|
|
const relatedGame2 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Bet2 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Bet2?.setGame) {
|
|
await Bet2.setGame(relatedGame2);
|
|
}
|
|
|
|
const relatedGame3 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Bet3 = await Bets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Bet3?.setGame) {
|
|
await Bet3.setGame(relatedGame3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateLeaderboardWithPlayer() {
|
|
const relatedPlayer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Leaderboard0 = await Leaderboards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Leaderboard0?.setPlayer) {
|
|
await Leaderboard0.setPlayer(relatedPlayer0);
|
|
}
|
|
|
|
const relatedPlayer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Leaderboard1 = await Leaderboards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Leaderboard1?.setPlayer) {
|
|
await Leaderboard1.setPlayer(relatedPlayer1);
|
|
}
|
|
|
|
const relatedPlayer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Leaderboard2 = await Leaderboards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Leaderboard2?.setPlayer) {
|
|
await Leaderboard2.setPlayer(relatedPlayer2);
|
|
}
|
|
|
|
const relatedPlayer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Leaderboard3 = await Leaderboards.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Leaderboard3?.setPlayer) {
|
|
await Leaderboard3.setPlayer(relatedPlayer3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Chats.bulkCreate(ChatsData);
|
|
|
|
await Bets.bulkCreate(BetsData);
|
|
|
|
await Games.bulkCreate(GamesData);
|
|
|
|
await Leaderboards.bulkCreate(LeaderboardsData);
|
|
|
|
await Promise.all([
|
|
await associateChatWithPlayer(),
|
|
|
|
await associateChatWithGame(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateBetWithPlayer(),
|
|
|
|
await associateBetWithGame(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateLeaderboardWithPlayer(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('chats', null, {});
|
|
|
|
await queryInterface.bulkDelete('bets', null, {});
|
|
|
|
await queryInterface.bulkDelete('games', null, {});
|
|
|
|
await queryInterface.bulkDelete('leaderboards', null, {});
|
|
},
|
|
};
|