31818/backend/src/db/seeders/20231127130745-sample-data.js
2025-05-28 13:39:48 +00:00

834 lines
18 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Auctions = db.auctions;
const Bids = db.bids;
const Leagues = db.leagues;
const Matches = db.matches;
const News = db.news;
const Players = db.players;
const Teams = db.teams;
const AuctionsData = [
{
auction_date: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_many" field
},
{
auction_date: new Date('2023-10-15T10:00:00Z'),
// type code here for "relation_many" field
},
{
auction_date: new Date('2023-11-01T10:00:00Z'),
// type code here for "relation_many" field
},
{
auction_date: new Date('2023-11-15T10:00:00Z'),
// type code here for "relation_many" field
},
{
auction_date: new Date('2023-12-01T10:00:00Z'),
// type code here for "relation_many" field
},
];
const BidsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
amount: 50000,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
amount: 45000,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
amount: 55000,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
amount: 60000,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
amount: 40000,
},
];
const LeaguesData = [
{
name: 'VTUKPL 2023',
start_date: new Date('2023-11-01T00:00:00Z'),
end_date: new Date('2023-12-15T00:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'VTUKPL 2024',
start_date: new Date('2024-01-10T00:00:00Z'),
end_date: new Date('2024-03-20T00:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'VTUKPL Summer Cup',
start_date: new Date('2023-06-01T00:00:00Z'),
end_date: new Date('2023-07-15T00:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'VTUKPL Winter Series',
start_date: new Date('2023-12-01T00:00:00Z'),
end_date: new Date('2024-01-15T00:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
name: 'VTUKPL Invitational',
start_date: new Date('2023-09-01T00:00:00Z'),
end_date: new Date('2023-10-15T00:00:00Z'),
// type code here for "relation_many" field
// type code here for "relation_many" field
},
];
const MatchesData = [
{
match_date: new Date('2023-11-05T14:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
home_score: 250,
away_score: 240,
},
{
match_date: new Date('2023-11-12T14:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
home_score: 220,
away_score: 230,
},
{
match_date: new Date('2023-11-19T14:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
home_score: 210,
away_score: 215,
},
{
match_date: new Date('2023-11-26T14:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
home_score: 200,
away_score: 205,
},
{
match_date: new Date('2023-12-03T14:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
home_score: 240,
away_score: 245,
},
];
const NewsData = [
{
title: 'VTUKPL 2023 Kicks Off',
content:
'The VTUKPL 2023 season has officially started with exciting matches lined up.',
published_date: new Date('2023-11-01T09:00:00Z'),
},
{
title: 'Thunderbolts Win Opening Match',
content:
'Thunderbolts secured a thrilling victory in the opening match against Warriors.',
published_date: new Date('2023-11-05T18:00:00Z'),
},
{
title: 'Player Auction Results Announced',
content:
'The player auction concluded with record-breaking bids for top players.',
published_date: new Date('2023-10-02T12:00:00Z'),
},
{
title: 'Dragons vs Titans: A Close Encounter',
content: 'Dragons narrowly defeated Titans in a nail-biting finish.',
published_date: new Date('2023-11-12T18:00:00Z'),
},
{
title: 'Eagles Soar to Victory',
content:
'Eagles clinched a win against Thunderbolts in a high-scoring match.',
published_date: new Date('2023-11-19T18:00:00Z'),
},
];
const PlayersData = [
{
name: 'Alex Johnson',
age: 28,
position: 'Batsman',
// type code here for "relation_one" field
},
{
name: 'Chris Martin',
age: 30,
position: 'Bowler',
// type code here for "relation_one" field
},
{
name: 'David Brown',
age: 25,
position: 'All-rounder',
// type code here for "relation_one" field
},
{
name: 'Ethan White',
age: 27,
position: 'Wicketkeeper',
// type code here for "relation_one" field
},
{
name: 'Liam Green',
age: 22,
position: 'Batsman',
// type code here for "relation_one" field
},
];
const TeamsData = [
{
name: 'Thunderbolts',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Warriors',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Dragons',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Titans',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Eagles',
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateBidWithPlayer() {
const relatedPlayer0 = await Players.findOne({
offset: Math.floor(Math.random() * (await Players.count())),
});
const Bid0 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Bid0?.setPlayer) {
await Bid0.setPlayer(relatedPlayer0);
}
const relatedPlayer1 = await Players.findOne({
offset: Math.floor(Math.random() * (await Players.count())),
});
const Bid1 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Bid1?.setPlayer) {
await Bid1.setPlayer(relatedPlayer1);
}
const relatedPlayer2 = await Players.findOne({
offset: Math.floor(Math.random() * (await Players.count())),
});
const Bid2 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Bid2?.setPlayer) {
await Bid2.setPlayer(relatedPlayer2);
}
const relatedPlayer3 = await Players.findOne({
offset: Math.floor(Math.random() * (await Players.count())),
});
const Bid3 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Bid3?.setPlayer) {
await Bid3.setPlayer(relatedPlayer3);
}
const relatedPlayer4 = await Players.findOne({
offset: Math.floor(Math.random() * (await Players.count())),
});
const Bid4 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Bid4?.setPlayer) {
await Bid4.setPlayer(relatedPlayer4);
}
}
async function associateBidWithTeam() {
const relatedTeam0 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Bid0 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Bid0?.setTeam) {
await Bid0.setTeam(relatedTeam0);
}
const relatedTeam1 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Bid1 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Bid1?.setTeam) {
await Bid1.setTeam(relatedTeam1);
}
const relatedTeam2 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Bid2 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Bid2?.setTeam) {
await Bid2.setTeam(relatedTeam2);
}
const relatedTeam3 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Bid3 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Bid3?.setTeam) {
await Bid3.setTeam(relatedTeam3);
}
const relatedTeam4 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Bid4 = await Bids.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Bid4?.setTeam) {
await Bid4.setTeam(relatedTeam4);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateMatchWithHome_team() {
const relatedHome_team0 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match0 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Match0?.setHome_team) {
await Match0.setHome_team(relatedHome_team0);
}
const relatedHome_team1 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match1 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Match1?.setHome_team) {
await Match1.setHome_team(relatedHome_team1);
}
const relatedHome_team2 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match2 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Match2?.setHome_team) {
await Match2.setHome_team(relatedHome_team2);
}
const relatedHome_team3 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match3 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Match3?.setHome_team) {
await Match3.setHome_team(relatedHome_team3);
}
const relatedHome_team4 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match4 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Match4?.setHome_team) {
await Match4.setHome_team(relatedHome_team4);
}
}
async function associateMatchWithAway_team() {
const relatedAway_team0 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match0 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Match0?.setAway_team) {
await Match0.setAway_team(relatedAway_team0);
}
const relatedAway_team1 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match1 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Match1?.setAway_team) {
await Match1.setAway_team(relatedAway_team1);
}
const relatedAway_team2 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match2 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Match2?.setAway_team) {
await Match2.setAway_team(relatedAway_team2);
}
const relatedAway_team3 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match3 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Match3?.setAway_team) {
await Match3.setAway_team(relatedAway_team3);
}
const relatedAway_team4 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Match4 = await Matches.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Match4?.setAway_team) {
await Match4.setAway_team(relatedAway_team4);
}
}
async function associatePlayerWithTeam() {
const relatedTeam0 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Player0 = await Players.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Player0?.setTeam) {
await Player0.setTeam(relatedTeam0);
}
const relatedTeam1 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Player1 = await Players.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Player1?.setTeam) {
await Player1.setTeam(relatedTeam1);
}
const relatedTeam2 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Player2 = await Players.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Player2?.setTeam) {
await Player2.setTeam(relatedTeam2);
}
const relatedTeam3 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Player3 = await Players.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Player3?.setTeam) {
await Player3.setTeam(relatedTeam3);
}
const relatedTeam4 = await Teams.findOne({
offset: Math.floor(Math.random() * (await Teams.count())),
});
const Player4 = await Players.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Player4?.setTeam) {
await Player4.setTeam(relatedTeam4);
}
}
async function associateTeamWithLeague() {
const relatedLeague0 = await Leagues.findOne({
offset: Math.floor(Math.random() * (await Leagues.count())),
});
const Team0 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Team0?.setLeague) {
await Team0.setLeague(relatedLeague0);
}
const relatedLeague1 = await Leagues.findOne({
offset: Math.floor(Math.random() * (await Leagues.count())),
});
const Team1 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Team1?.setLeague) {
await Team1.setLeague(relatedLeague1);
}
const relatedLeague2 = await Leagues.findOne({
offset: Math.floor(Math.random() * (await Leagues.count())),
});
const Team2 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Team2?.setLeague) {
await Team2.setLeague(relatedLeague2);
}
const relatedLeague3 = await Leagues.findOne({
offset: Math.floor(Math.random() * (await Leagues.count())),
});
const Team3 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Team3?.setLeague) {
await Team3.setLeague(relatedLeague3);
}
const relatedLeague4 = await Leagues.findOne({
offset: Math.floor(Math.random() * (await Leagues.count())),
});
const Team4 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Team4?.setLeague) {
await Team4.setLeague(relatedLeague4);
}
}
// Similar logic for "relation_many"
async function associateTeamWithManager() {
const relatedManager0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Team0 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Team0?.setManager) {
await Team0.setManager(relatedManager0);
}
const relatedManager1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Team1 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Team1?.setManager) {
await Team1.setManager(relatedManager1);
}
const relatedManager2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Team2 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Team2?.setManager) {
await Team2.setManager(relatedManager2);
}
const relatedManager3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Team3 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Team3?.setManager) {
await Team3.setManager(relatedManager3);
}
const relatedManager4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Team4 = await Teams.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Team4?.setManager) {
await Team4.setManager(relatedManager4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Auctions.bulkCreate(AuctionsData);
await Bids.bulkCreate(BidsData);
await Leagues.bulkCreate(LeaguesData);
await Matches.bulkCreate(MatchesData);
await News.bulkCreate(NewsData);
await Players.bulkCreate(PlayersData);
await Teams.bulkCreate(TeamsData);
await Promise.all([
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateBidWithPlayer(),
await associateBidWithTeam(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateMatchWithHome_team(),
await associateMatchWithAway_team(),
await associatePlayerWithTeam(),
await associateTeamWithLeague(),
// Similar logic for "relation_many"
await associateTeamWithManager(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('auctions', null, {});
await queryInterface.bulkDelete('bids', null, {});
await queryInterface.bulkDelete('leagues', null, {});
await queryInterface.bulkDelete('matches', null, {});
await queryInterface.bulkDelete('news', null, {});
await queryInterface.bulkDelete('players', null, {});
await queryInterface.bulkDelete('teams', null, {});
},
};