668 lines
14 KiB
JavaScript
668 lines
14 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Contests = db.contests;
|
|
|
|
const Matches = db.matches;
|
|
|
|
const Players = db.players;
|
|
|
|
const Sports = db.sports;
|
|
|
|
const Teams = db.teams;
|
|
|
|
const Transactions = db.transactions;
|
|
|
|
const Wallets = db.wallets;
|
|
|
|
const ContestsData = [
|
|
{
|
|
name: 'Mega Contest',
|
|
|
|
type: 'private',
|
|
|
|
entry_fee: 50,
|
|
|
|
prize_pool: 5000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Practice Contest',
|
|
|
|
type: 'head_to_head',
|
|
|
|
entry_fee: 0,
|
|
|
|
prize_pool: 0,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Private League',
|
|
|
|
type: 'private',
|
|
|
|
entry_fee: 20,
|
|
|
|
prize_pool: 2000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Head-to-Head Battle',
|
|
|
|
type: 'paid',
|
|
|
|
entry_fee: 10,
|
|
|
|
prize_pool: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MatchesData = [
|
|
{
|
|
title: 'India vs Australia',
|
|
|
|
start_time: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-01T18:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Real Madrid vs Barcelona',
|
|
|
|
start_time: new Date('2023-11-02T20:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-02T22:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Lakers vs Celtics',
|
|
|
|
start_time: new Date('2023-11-03T02:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-03T04:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Yankees vs Red Sox',
|
|
|
|
start_time: new Date('2023-11-04T19:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-04T22:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PlayersData = [
|
|
{
|
|
name: 'Virat Kohli',
|
|
|
|
role: 'allrounder',
|
|
|
|
credit_value: 10.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Lionel Messi',
|
|
|
|
role: 'allrounder',
|
|
|
|
credit_value: 12,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'LeBron James',
|
|
|
|
role: 'wicketkeeper',
|
|
|
|
credit_value: 11.5,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Tom Brady',
|
|
|
|
role: 'bowler',
|
|
|
|
credit_value: 9,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SportsData = [
|
|
{
|
|
name: 'Cricket',
|
|
|
|
description: 'A bat-and-ball game played between two teams.',
|
|
},
|
|
|
|
{
|
|
name: 'Football',
|
|
|
|
description: 'A team sport played with a spherical ball.',
|
|
},
|
|
|
|
{
|
|
name: 'Basketball',
|
|
|
|
description: 'A game played between two teams of five players.',
|
|
},
|
|
|
|
{
|
|
name: 'Hockey',
|
|
|
|
description:
|
|
"A sport in which two teams play against each other by trying to maneuver a ball into the opponent's goal.",
|
|
},
|
|
];
|
|
|
|
const TeamsData = [
|
|
{
|
|
name: 'Team Alpha',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Team Beta',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Team Gamma',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Team Delta',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TransactionsData = [
|
|
{
|
|
amount: 100,
|
|
|
|
type: 'deposit',
|
|
|
|
transaction_date: new Date('2023-10-01T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 50,
|
|
|
|
type: 'winnings',
|
|
|
|
transaction_date: new Date('2023-10-02T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 200,
|
|
|
|
type: 'deposit',
|
|
|
|
transaction_date: new Date('2023-10-03T16:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 75,
|
|
|
|
type: 'entry_fee',
|
|
|
|
transaction_date: new Date('2023-10-04T18:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const WalletsData = [
|
|
{
|
|
balance: 500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
balance: 300,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
balance: 700,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
balance: 250,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateContestWithMatch() {
|
|
const relatedMatch0 = await Matches.findOne({
|
|
offset: Math.floor(Math.random() * (await Matches.count())),
|
|
});
|
|
const Contest0 = await Contests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Contest0?.setMatch) {
|
|
await Contest0.setMatch(relatedMatch0);
|
|
}
|
|
|
|
const relatedMatch1 = await Matches.findOne({
|
|
offset: Math.floor(Math.random() * (await Matches.count())),
|
|
});
|
|
const Contest1 = await Contests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Contest1?.setMatch) {
|
|
await Contest1.setMatch(relatedMatch1);
|
|
}
|
|
|
|
const relatedMatch2 = await Matches.findOne({
|
|
offset: Math.floor(Math.random() * (await Matches.count())),
|
|
});
|
|
const Contest2 = await Contests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Contest2?.setMatch) {
|
|
await Contest2.setMatch(relatedMatch2);
|
|
}
|
|
|
|
const relatedMatch3 = await Matches.findOne({
|
|
offset: Math.floor(Math.random() * (await Matches.count())),
|
|
});
|
|
const Contest3 = await Contests.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Contest3?.setMatch) {
|
|
await Contest3.setMatch(relatedMatch3);
|
|
}
|
|
}
|
|
|
|
async function associateMatchWithSport() {
|
|
const relatedSport0 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Match0 = await Matches.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Match0?.setSport) {
|
|
await Match0.setSport(relatedSport0);
|
|
}
|
|
|
|
const relatedSport1 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Match1 = await Matches.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Match1?.setSport) {
|
|
await Match1.setSport(relatedSport1);
|
|
}
|
|
|
|
const relatedSport2 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Match2 = await Matches.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Match2?.setSport) {
|
|
await Match2.setSport(relatedSport2);
|
|
}
|
|
|
|
const relatedSport3 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Match3 = await Matches.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Match3?.setSport) {
|
|
await Match3.setSport(relatedSport3);
|
|
}
|
|
}
|
|
|
|
async function associatePlayerWithSport() {
|
|
const relatedSport0 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Player0 = await Players.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Player0?.setSport) {
|
|
await Player0.setSport(relatedSport0);
|
|
}
|
|
|
|
const relatedSport1 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Player1 = await Players.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Player1?.setSport) {
|
|
await Player1.setSport(relatedSport1);
|
|
}
|
|
|
|
const relatedSport2 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Player2 = await Players.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Player2?.setSport) {
|
|
await Player2.setSport(relatedSport2);
|
|
}
|
|
|
|
const relatedSport3 = await Sports.findOne({
|
|
offset: Math.floor(Math.random() * (await Sports.count())),
|
|
});
|
|
const Player3 = await Players.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Player3?.setSport) {
|
|
await Player3.setSport(relatedSport3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateTeamWithCaptain() {
|
|
const relatedCaptain0 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team0 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Team0?.setCaptain) {
|
|
await Team0.setCaptain(relatedCaptain0);
|
|
}
|
|
|
|
const relatedCaptain1 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team1 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Team1?.setCaptain) {
|
|
await Team1.setCaptain(relatedCaptain1);
|
|
}
|
|
|
|
const relatedCaptain2 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team2 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Team2?.setCaptain) {
|
|
await Team2.setCaptain(relatedCaptain2);
|
|
}
|
|
|
|
const relatedCaptain3 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team3 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Team3?.setCaptain) {
|
|
await Team3.setCaptain(relatedCaptain3);
|
|
}
|
|
}
|
|
|
|
async function associateTeamWithVice_captain() {
|
|
const relatedVice_captain0 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team0 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Team0?.setVice_captain) {
|
|
await Team0.setVice_captain(relatedVice_captain0);
|
|
}
|
|
|
|
const relatedVice_captain1 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team1 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Team1?.setVice_captain) {
|
|
await Team1.setVice_captain(relatedVice_captain1);
|
|
}
|
|
|
|
const relatedVice_captain2 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team2 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Team2?.setVice_captain) {
|
|
await Team2.setVice_captain(relatedVice_captain2);
|
|
}
|
|
|
|
const relatedVice_captain3 = await Players.findOne({
|
|
offset: Math.floor(Math.random() * (await Players.count())),
|
|
});
|
|
const Team3 = await Teams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Team3?.setVice_captain) {
|
|
await Team3.setVice_captain(relatedVice_captain3);
|
|
}
|
|
}
|
|
|
|
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 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 Contests.bulkCreate(ContestsData);
|
|
|
|
await Matches.bulkCreate(MatchesData);
|
|
|
|
await Players.bulkCreate(PlayersData);
|
|
|
|
await Sports.bulkCreate(SportsData);
|
|
|
|
await Teams.bulkCreate(TeamsData);
|
|
|
|
await Transactions.bulkCreate(TransactionsData);
|
|
|
|
await Wallets.bulkCreate(WalletsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateContestWithMatch(),
|
|
|
|
await associateMatchWithSport(),
|
|
|
|
await associatePlayerWithSport(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTeamWithCaptain(),
|
|
|
|
await associateTeamWithVice_captain(),
|
|
|
|
await associateTransactionWithUser(),
|
|
|
|
await associateWalletWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('contests', null, {});
|
|
|
|
await queryInterface.bulkDelete('matches', null, {});
|
|
|
|
await queryInterface.bulkDelete('players', null, {});
|
|
|
|
await queryInterface.bulkDelete('sports', null, {});
|
|
|
|
await queryInterface.bulkDelete('teams', null, {});
|
|
|
|
await queryInterface.bulkDelete('transactions', null, {});
|
|
|
|
await queryInterface.bulkDelete('wallets', null, {});
|
|
},
|
|
};
|