39053-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-08 16:51:04 +00:00

1935 lines
37 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const GameHubs = db.game_hubs;
const Games = db.games;
const GameSessions = db.game_sessions;
const GameScores = db.game_scores;
const Announcements = db.announcements;
const GameHubsData = [
{
"name": "Many Games",
"slug": "many-games",
"canonical_url": "https://tickets.blackbearshow.com/docs",
"headline": "Pick a game and play instantly",
"theme_color": "#39FF14",
"description": "A bright and simple hub for quick browser games. Choose a title, play in your tab, then come back for more.",
// type code here for "images" field
"is_published": true,
"published_at": new Date('2026-03-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
"name": "Monkey Games Showcase",
"slug": "monkey-games-showcase",
"canonical_url": "https://tickets.blackbearshow.com/docs/showcase",
"headline": "Featured picks of the week",
"theme_color": "#00D1FF",
"description": "A rotating selection of featured games curated by the team.",
// type code here for "images" field
"is_published": true,
"published_at": new Date('2026-03-02T10:00:00Z'),
// type code here for "relation_one" field
},
{
"name": "New Arrivals",
"slug": "new-arrivals",
"canonical_url": "https://tickets.blackbearshow.com/docs/new",
"headline": "Fresh games to try",
"theme_color": "#FFB000",
"description": "Recently added games and experiments.",
// type code here for "images" field
"is_published": false,
"published_at": new Date('2026-03-10T10:00:00Z'),
// type code here for "relation_one" field
},
];
const GamesData = [
{
"title": "Banana Click Rush",
"slug": "banana-click-rush",
"game_type": "external_link",
"launch_url": "https://tickets.blackbearshow.com/docs/games/banana-click-rush",
"embed_url": "https://tickets.blackbearshow.com/docs/games/banana-click-rush/embed",
// type code here for "files" field
"instructions": "Click bananas quickly to build a combo and beat your best score.",
// type code here for "images" field
"status": "published",
"featured": true,
"sort_order": 10,
"release_at": new Date('2026-03-01T12:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Jungle Memory Match",
"slug": "jungle-memory-match",
"game_type": "upload",
"launch_url": "https://tickets.blackbearshow.com/docs/games/jungle-memory-match",
"embed_url": "https://tickets.blackbearshow.com/docs/games/jungle-memory-match/embed",
// type code here for "files" field
"instructions": "Flip cards to find matching pairs. Fewer moves is better.",
// type code here for "images" field
"status": "archived",
"featured": true,
"sort_order": 20,
"release_at": new Date('2026-03-02T12:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Coconut Drop",
"slug": "coconut-drop",
"game_type": "external_link",
"launch_url": "https://example-games.example/coconut-drop",
"embed_url": "",
// type code here for "files" field
"instructions": "Catch falling coconuts and avoid obstacles. Survive as long as you can.",
// type code here for "images" field
"status": "published",
"featured": true,
"sort_order": 30,
"release_at": new Date('2026-03-03T12:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const GameSessionsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"started_at": new Date('2026-03-07T12:05:00Z'),
"ended_at": new Date('2026-03-07T12:12:40Z'),
"duration_seconds": 460,
"client_ip": "203.0.113.10",
"user_agent": "Mozilla/5.0 Windows NT 10.0 Win64 x64 AppleWebKit/537.36",
"end_reason": "quit",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"started_at": new Date('2026-03-07T13:20:10Z'),
"ended_at": new Date('2026-03-07T13:29:02Z'),
"duration_seconds": 532,
"client_ip": "198.51.100.22",
"user_agent": "Mozilla/5.0 Mac OS X 10_15_7 AppleWebKit/605.1.15",
"end_reason": "timeout",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"started_at": new Date('2026-03-06T19:44:15Z'),
"ended_at": new Date('2026-03-06T19:51:55Z'),
"duration_seconds": 460,
"client_ip": "203.0.113.10",
"user_agent": "Mozilla/5.0 iPhone CPU iPhone OS 17_2 like Mac OS X AppleWebKit/605.1.15",
"end_reason": "timeout",
},
];
const GameScoresData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"score_value": 1240,
"score_label": "Top Combo",
"score_type": "points",
"achieved_at": new Date('2026-03-07T12:12:30Z'),
"metadata_json": "{combo:42,clicks:310}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"score_value": 58,
"score_label": "Best Moves",
"score_type": "high_score",
"achieved_at": new Date('2026-03-07T13:28:50Z'),
"metadata_json": "{pairs:12,mode:standard}",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"score_value": 96,
"score_label": "Survival Time",
"score_type": "high_score",
"achieved_at": new Date('2026-03-06T19:51:40Z'),
"metadata_json": "{difficulty:normal}",
},
];
const AnnouncementsData = [
{
"title": "Welcome to Monkey Games",
"body": "Many Games is live. Choose a game, play instantly, and return here to try another title.",
"audience": "all",
"is_active": true,
"starts_at": new Date('2026-03-01T10:00:00Z'),
"ends_at": new Date('2026-04-01T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Featured games updated",
"body": "This week we are highlighting Banana Click Rush and Jungle Memory Match. New picks land every Monday.",
"audience": "admins",
"is_active": true,
"starts_at": new Date('2026-03-04T09:00:00Z'),
"ends_at": new Date('2026-03-11T09:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Maintenance window",
"body": "Brief maintenance is scheduled. Game embeds may load slowly during the window.",
"audience": "visitors",
"is_active": true,
"starts_at": new Date('2026-03-09T01:00:00Z'),
"ends_at": new Date('2026-03-09T01:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
async function associateGameHubWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameHub0 = await GameHubs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (GameHub0?.setOwner)
{
await
GameHub0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameHub1 = await GameHubs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (GameHub1?.setOwner)
{
await
GameHub1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameHub2 = await GameHubs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (GameHub2?.setOwner)
{
await
GameHub2.
setOwner(relatedOwner2);
}
}
async function associateGameWithHub() {
const relatedHub0 = await GameHubs.findOne({
offset: Math.floor(Math.random() * (await GameHubs.count())),
});
const Game0 = await Games.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Game0?.setHub)
{
await
Game0.
setHub(relatedHub0);
}
const relatedHub1 = await GameHubs.findOne({
offset: Math.floor(Math.random() * (await GameHubs.count())),
});
const Game1 = await Games.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Game1?.setHub)
{
await
Game1.
setHub(relatedHub1);
}
const relatedHub2 = await GameHubs.findOne({
offset: Math.floor(Math.random() * (await GameHubs.count())),
});
const Game2 = await Games.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Game2?.setHub)
{
await
Game2.
setHub(relatedHub2);
}
}
async function associateGameWithCreated_by_user() {
const relatedCreated_by_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Game0 = await Games.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Game0?.setCreated_by_user)
{
await
Game0.
setCreated_by_user(relatedCreated_by_user0);
}
const relatedCreated_by_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Game1 = await Games.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Game1?.setCreated_by_user)
{
await
Game1.
setCreated_by_user(relatedCreated_by_user1);
}
const relatedCreated_by_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Game2 = await Games.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Game2?.setCreated_by_user)
{
await
Game2.
setCreated_by_user(relatedCreated_by_user2);
}
}
async function associateGameSessionWithGame() {
const relatedGame0 = await Games.findOne({
offset: Math.floor(Math.random() * (await Games.count())),
});
const GameSession0 = await GameSessions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (GameSession0?.setGame)
{
await
GameSession0.
setGame(relatedGame0);
}
const relatedGame1 = await Games.findOne({
offset: Math.floor(Math.random() * (await Games.count())),
});
const GameSession1 = await GameSessions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (GameSession1?.setGame)
{
await
GameSession1.
setGame(relatedGame1);
}
const relatedGame2 = await Games.findOne({
offset: Math.floor(Math.random() * (await Games.count())),
});
const GameSession2 = await GameSessions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (GameSession2?.setGame)
{
await
GameSession2.
setGame(relatedGame2);
}
}
async function associateGameSessionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameSession0 = await GameSessions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (GameSession0?.setUser)
{
await
GameSession0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameSession1 = await GameSessions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (GameSession1?.setUser)
{
await
GameSession1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameSession2 = await GameSessions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (GameSession2?.setUser)
{
await
GameSession2.
setUser(relatedUser2);
}
}
async function associateGameScoreWithGame() {
const relatedGame0 = await Games.findOne({
offset: Math.floor(Math.random() * (await Games.count())),
});
const GameScore0 = await GameScores.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (GameScore0?.setGame)
{
await
GameScore0.
setGame(relatedGame0);
}
const relatedGame1 = await Games.findOne({
offset: Math.floor(Math.random() * (await Games.count())),
});
const GameScore1 = await GameScores.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (GameScore1?.setGame)
{
await
GameScore1.
setGame(relatedGame1);
}
const relatedGame2 = await Games.findOne({
offset: Math.floor(Math.random() * (await Games.count())),
});
const GameScore2 = await GameScores.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (GameScore2?.setGame)
{
await
GameScore2.
setGame(relatedGame2);
}
}
async function associateGameScoreWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameScore0 = await GameScores.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (GameScore0?.setUser)
{
await
GameScore0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameScore1 = await GameScores.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (GameScore1?.setUser)
{
await
GameScore1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const GameScore2 = await GameScores.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (GameScore2?.setUser)
{
await
GameScore2.
setUser(relatedUser2);
}
}
async function associateAnnouncementWithHub() {
const relatedHub0 = await GameHubs.findOne({
offset: Math.floor(Math.random() * (await GameHubs.count())),
});
const Announcement0 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Announcement0?.setHub)
{
await
Announcement0.
setHub(relatedHub0);
}
const relatedHub1 = await GameHubs.findOne({
offset: Math.floor(Math.random() * (await GameHubs.count())),
});
const Announcement1 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Announcement1?.setHub)
{
await
Announcement1.
setHub(relatedHub1);
}
const relatedHub2 = await GameHubs.findOne({
offset: Math.floor(Math.random() * (await GameHubs.count())),
});
const Announcement2 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Announcement2?.setHub)
{
await
Announcement2.
setHub(relatedHub2);
}
}
async function associateAnnouncementWithCreated_by_user() {
const relatedCreated_by_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Announcement0 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Announcement0?.setCreated_by_user)
{
await
Announcement0.
setCreated_by_user(relatedCreated_by_user0);
}
const relatedCreated_by_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Announcement1 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Announcement1?.setCreated_by_user)
{
await
Announcement1.
setCreated_by_user(relatedCreated_by_user1);
}
const relatedCreated_by_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Announcement2 = await Announcements.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Announcement2?.setCreated_by_user)
{
await
Announcement2.
setCreated_by_user(relatedCreated_by_user2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await GameHubs.bulkCreate(GameHubsData);
await Games.bulkCreate(GamesData);
await GameSessions.bulkCreate(GameSessionsData);
await GameScores.bulkCreate(GameScoresData);
await Announcements.bulkCreate(AnnouncementsData);
await Promise.all([
// Similar logic for "relation_many"
await associateGameHubWithOwner(),
await associateGameWithHub(),
await associateGameWithCreated_by_user(),
await associateGameSessionWithGame(),
await associateGameSessionWithUser(),
await associateGameScoreWithGame(),
await associateGameScoreWithUser(),
await associateAnnouncementWithHub(),
await associateAnnouncementWithCreated_by_user(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('game_hubs', null, {});
await queryInterface.bulkDelete('games', null, {});
await queryInterface.bulkDelete('game_sessions', null, {});
await queryInterface.bulkDelete('game_scores', null, {});
await queryInterface.bulkDelete('announcements', null, {});
},
};