615 lines
13 KiB
JavaScript
615 lines
13 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Games = db.games;
|
|
|
|
const Groups = db.groups;
|
|
|
|
const Purchases = db.purchases;
|
|
|
|
const Scores = db.scores;
|
|
|
|
const Grupo = db.grupo;
|
|
|
|
const GamesData = [
|
|
{
|
|
title: 'Avionsito Esquiva',
|
|
|
|
category: 'AvionsitoEsquiva',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Ahorcado Infantil',
|
|
|
|
category: 'TetrisKids',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Tetris Kids',
|
|
|
|
category: 'TetrisKids',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Snake Evolutiva',
|
|
|
|
category: 'AvionsitoEsquiva',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const GroupsData = [
|
|
{
|
|
name: 'Group Alpha',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Group Beta',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Group Gamma',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Group Delta',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PurchasesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
pro_version: true,
|
|
|
|
purchase_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
pro_version: true,
|
|
|
|
purchase_date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
pro_version: true,
|
|
|
|
purchase_date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
pro_version: true,
|
|
|
|
purchase_date: new Date('2023-10-04T13:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ScoresData = [
|
|
{
|
|
points: 1500,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
points: 1200,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
points: 1800,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
points: 2000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const GrupoData = [
|
|
{
|
|
name: 'John von Neumann',
|
|
},
|
|
|
|
{
|
|
name: 'Alfred Wegener',
|
|
},
|
|
|
|
{
|
|
name: 'Stephen Hawking',
|
|
},
|
|
|
|
{
|
|
name: 'Justus Liebig',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithGrupo() {
|
|
const relatedGrupo0 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setGrupo) {
|
|
await User0.setGrupo(relatedGrupo0);
|
|
}
|
|
|
|
const relatedGrupo1 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setGrupo) {
|
|
await User1.setGrupo(relatedGrupo1);
|
|
}
|
|
|
|
const relatedGrupo2 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setGrupo) {
|
|
await User2.setGrupo(relatedGrupo2);
|
|
}
|
|
|
|
const relatedGrupo3 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setGrupo) {
|
|
await User3.setGrupo(relatedGrupo3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateGameWithGrupo() {
|
|
const relatedGrupo0 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Game0 = await Games.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Game0?.setGrupo) {
|
|
await Game0.setGrupo(relatedGrupo0);
|
|
}
|
|
|
|
const relatedGrupo1 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Game1 = await Games.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Game1?.setGrupo) {
|
|
await Game1.setGrupo(relatedGrupo1);
|
|
}
|
|
|
|
const relatedGrupo2 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Game2 = await Games.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Game2?.setGrupo) {
|
|
await Game2.setGrupo(relatedGrupo2);
|
|
}
|
|
|
|
const relatedGrupo3 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Game3 = await Games.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Game3?.setGrupo) {
|
|
await Game3.setGrupo(relatedGrupo3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateGroupWithGrupo() {
|
|
const relatedGrupo0 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Group0 = await Groups.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Group0?.setGrupo) {
|
|
await Group0.setGrupo(relatedGrupo0);
|
|
}
|
|
|
|
const relatedGrupo1 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Group1 = await Groups.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Group1?.setGrupo) {
|
|
await Group1.setGrupo(relatedGrupo1);
|
|
}
|
|
|
|
const relatedGrupo2 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Group2 = await Groups.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Group2?.setGrupo) {
|
|
await Group2.setGrupo(relatedGrupo2);
|
|
}
|
|
|
|
const relatedGrupo3 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Group3 = await Groups.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Group3?.setGrupo) {
|
|
await Group3.setGrupo(relatedGrupo3);
|
|
}
|
|
}
|
|
|
|
async function associatePurchaseWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Purchase0 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Purchase0?.setUser) {
|
|
await Purchase0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Purchase1 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Purchase1?.setUser) {
|
|
await Purchase1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Purchase2 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Purchase2?.setUser) {
|
|
await Purchase2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Purchase3 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Purchase3?.setUser) {
|
|
await Purchase3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associatePurchaseWithGrupo() {
|
|
const relatedGrupo0 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Purchase0 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Purchase0?.setGrupo) {
|
|
await Purchase0.setGrupo(relatedGrupo0);
|
|
}
|
|
|
|
const relatedGrupo1 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Purchase1 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Purchase1?.setGrupo) {
|
|
await Purchase1.setGrupo(relatedGrupo1);
|
|
}
|
|
|
|
const relatedGrupo2 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Purchase2 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Purchase2?.setGrupo) {
|
|
await Purchase2.setGrupo(relatedGrupo2);
|
|
}
|
|
|
|
const relatedGrupo3 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Purchase3 = await Purchases.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Purchase3?.setGrupo) {
|
|
await Purchase3.setGrupo(relatedGrupo3);
|
|
}
|
|
}
|
|
|
|
async function associateScoreWithPlayer() {
|
|
const relatedPlayer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Score0 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Score0?.setPlayer) {
|
|
await Score0.setPlayer(relatedPlayer0);
|
|
}
|
|
|
|
const relatedPlayer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Score1 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Score1?.setPlayer) {
|
|
await Score1.setPlayer(relatedPlayer1);
|
|
}
|
|
|
|
const relatedPlayer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Score2 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Score2?.setPlayer) {
|
|
await Score2.setPlayer(relatedPlayer2);
|
|
}
|
|
|
|
const relatedPlayer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Score3 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Score3?.setPlayer) {
|
|
await Score3.setPlayer(relatedPlayer3);
|
|
}
|
|
}
|
|
|
|
async function associateScoreWithGame() {
|
|
const relatedGame0 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Score0 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Score0?.setGame) {
|
|
await Score0.setGame(relatedGame0);
|
|
}
|
|
|
|
const relatedGame1 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Score1 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Score1?.setGame) {
|
|
await Score1.setGame(relatedGame1);
|
|
}
|
|
|
|
const relatedGame2 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Score2 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Score2?.setGame) {
|
|
await Score2.setGame(relatedGame2);
|
|
}
|
|
|
|
const relatedGame3 = await Games.findOne({
|
|
offset: Math.floor(Math.random() * (await Games.count())),
|
|
});
|
|
const Score3 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Score3?.setGame) {
|
|
await Score3.setGame(relatedGame3);
|
|
}
|
|
}
|
|
|
|
async function associateScoreWithGrupo() {
|
|
const relatedGrupo0 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Score0 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Score0?.setGrupo) {
|
|
await Score0.setGrupo(relatedGrupo0);
|
|
}
|
|
|
|
const relatedGrupo1 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Score1 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Score1?.setGrupo) {
|
|
await Score1.setGrupo(relatedGrupo1);
|
|
}
|
|
|
|
const relatedGrupo2 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Score2 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Score2?.setGrupo) {
|
|
await Score2.setGrupo(relatedGrupo2);
|
|
}
|
|
|
|
const relatedGrupo3 = await Grupo.findOne({
|
|
offset: Math.floor(Math.random() * (await Grupo.count())),
|
|
});
|
|
const Score3 = await Scores.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Score3?.setGrupo) {
|
|
await Score3.setGrupo(relatedGrupo3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Games.bulkCreate(GamesData);
|
|
|
|
await Groups.bulkCreate(GroupsData);
|
|
|
|
await Purchases.bulkCreate(PurchasesData);
|
|
|
|
await Scores.bulkCreate(ScoresData);
|
|
|
|
await Grupo.bulkCreate(GrupoData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithGrupo(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateGameWithGrupo(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateGroupWithGrupo(),
|
|
|
|
await associatePurchaseWithUser(),
|
|
|
|
await associatePurchaseWithGrupo(),
|
|
|
|
await associateScoreWithPlayer(),
|
|
|
|
await associateScoreWithGame(),
|
|
|
|
await associateScoreWithGrupo(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('games', null, {});
|
|
|
|
await queryInterface.bulkDelete('groups', null, {});
|
|
|
|
await queryInterface.bulkDelete('purchases', null, {});
|
|
|
|
await queryInterface.bulkDelete('scores', null, {});
|
|
|
|
await queryInterface.bulkDelete('grupo', null, {});
|
|
},
|
|
};
|