919 lines
21 KiB
JavaScript
919 lines
21 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Comments = db.comments;
|
|
|
|
const Flags = db.flags;
|
|
|
|
const Likes = db.likes;
|
|
|
|
const MusicTracks = db.music_tracks;
|
|
|
|
const Videos = db.videos;
|
|
|
|
const Teams = db.teams;
|
|
|
|
const CommentsData = [
|
|
{
|
|
content: 'Great video!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
comment_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Very informative, thanks!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
comment_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'I love this place!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
comment_date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: "Can't wait to try this.",
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
comment_date: new Date('2023-10-04T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const FlagsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
reason: 'Inappropriate content',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
reason: 'Copyright infringement',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
reason: 'Spam',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
reason: 'Hate speech',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const LikesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MusicTracksData = [
|
|
{
|
|
title: 'Summer Vibes',
|
|
|
|
artist: 'DJ Cool',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Chill Beats',
|
|
|
|
artist: 'Smooth Sound',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Dance Party',
|
|
|
|
artist: 'Club Mix',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Relaxing Tunes',
|
|
|
|
artist: 'Calm Waves',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const VideosData = [
|
|
{
|
|
title: 'Morning Routine',
|
|
|
|
description: 'A quick look at my morning routine.',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
upload_date: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Cooking Tips',
|
|
|
|
description: 'Easy cooking tips for beginners.',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
upload_date: new Date('2023-10-02T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Travel Vlog',
|
|
|
|
description: 'Exploring the beautiful city of Paris.',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
upload_date: new Date('2023-10-03T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Fitness Challenge',
|
|
|
|
description: 'Join me in this 30-day fitness challenge.',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
upload_date: new Date('2023-10-04T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TeamsData = [
|
|
{
|
|
name: 'Team Alpha',
|
|
},
|
|
|
|
{
|
|
name: 'Team Beta',
|
|
},
|
|
|
|
{
|
|
name: 'Team Gamma',
|
|
},
|
|
|
|
{
|
|
name: 'Team Delta',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithTeam() {
|
|
const relatedTeam0 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setTeam) {
|
|
await User0.setTeam(relatedTeam0);
|
|
}
|
|
|
|
const relatedTeam1 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setTeam) {
|
|
await User1.setTeam(relatedTeam1);
|
|
}
|
|
|
|
const relatedTeam2 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setTeam) {
|
|
await User2.setTeam(relatedTeam2);
|
|
}
|
|
|
|
const relatedTeam3 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setTeam) {
|
|
await User3.setTeam(relatedTeam3);
|
|
}
|
|
}
|
|
|
|
async function associateCommentWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment0 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Comment0?.setUser) {
|
|
await Comment0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment1 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Comment1?.setUser) {
|
|
await Comment1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment2 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Comment2?.setUser) {
|
|
await Comment2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Comment3 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Comment3?.setUser) {
|
|
await Comment3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associateCommentWithVideo() {
|
|
const relatedVideo0 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Comment0 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Comment0?.setVideo) {
|
|
await Comment0.setVideo(relatedVideo0);
|
|
}
|
|
|
|
const relatedVideo1 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Comment1 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Comment1?.setVideo) {
|
|
await Comment1.setVideo(relatedVideo1);
|
|
}
|
|
|
|
const relatedVideo2 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Comment2 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Comment2?.setVideo) {
|
|
await Comment2.setVideo(relatedVideo2);
|
|
}
|
|
|
|
const relatedVideo3 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Comment3 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Comment3?.setVideo) {
|
|
await Comment3.setVideo(relatedVideo3);
|
|
}
|
|
}
|
|
|
|
async function associateCommentWithTeam() {
|
|
const relatedTeam0 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Comment0 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Comment0?.setTeam) {
|
|
await Comment0.setTeam(relatedTeam0);
|
|
}
|
|
|
|
const relatedTeam1 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Comment1 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Comment1?.setTeam) {
|
|
await Comment1.setTeam(relatedTeam1);
|
|
}
|
|
|
|
const relatedTeam2 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Comment2 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Comment2?.setTeam) {
|
|
await Comment2.setTeam(relatedTeam2);
|
|
}
|
|
|
|
const relatedTeam3 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Comment3 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Comment3?.setTeam) {
|
|
await Comment3.setTeam(relatedTeam3);
|
|
}
|
|
}
|
|
|
|
async function associateFlagWithVideo() {
|
|
const relatedVideo0 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Flag0 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Flag0?.setVideo) {
|
|
await Flag0.setVideo(relatedVideo0);
|
|
}
|
|
|
|
const relatedVideo1 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Flag1 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Flag1?.setVideo) {
|
|
await Flag1.setVideo(relatedVideo1);
|
|
}
|
|
|
|
const relatedVideo2 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Flag2 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Flag2?.setVideo) {
|
|
await Flag2.setVideo(relatedVideo2);
|
|
}
|
|
|
|
const relatedVideo3 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Flag3 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Flag3?.setVideo) {
|
|
await Flag3.setVideo(relatedVideo3);
|
|
}
|
|
}
|
|
|
|
async function associateFlagWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Flag0 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Flag0?.setUser) {
|
|
await Flag0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Flag1 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Flag1?.setUser) {
|
|
await Flag1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Flag2 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Flag2?.setUser) {
|
|
await Flag2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Flag3 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Flag3?.setUser) {
|
|
await Flag3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associateFlagWithTeam() {
|
|
const relatedTeam0 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Flag0 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Flag0?.setTeam) {
|
|
await Flag0.setTeam(relatedTeam0);
|
|
}
|
|
|
|
const relatedTeam1 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Flag1 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Flag1?.setTeam) {
|
|
await Flag1.setTeam(relatedTeam1);
|
|
}
|
|
|
|
const relatedTeam2 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Flag2 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Flag2?.setTeam) {
|
|
await Flag2.setTeam(relatedTeam2);
|
|
}
|
|
|
|
const relatedTeam3 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Flag3 = await Flags.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Flag3?.setTeam) {
|
|
await Flag3.setTeam(relatedTeam3);
|
|
}
|
|
}
|
|
|
|
async function associateLikeWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Like0 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Like0?.setUser) {
|
|
await Like0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Like1 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Like1?.setUser) {
|
|
await Like1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Like2 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Like2?.setUser) {
|
|
await Like2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Like3 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Like3?.setUser) {
|
|
await Like3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associateLikeWithVideo() {
|
|
const relatedVideo0 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Like0 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Like0?.setVideo) {
|
|
await Like0.setVideo(relatedVideo0);
|
|
}
|
|
|
|
const relatedVideo1 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Like1 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Like1?.setVideo) {
|
|
await Like1.setVideo(relatedVideo1);
|
|
}
|
|
|
|
const relatedVideo2 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Like2 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Like2?.setVideo) {
|
|
await Like2.setVideo(relatedVideo2);
|
|
}
|
|
|
|
const relatedVideo3 = await Videos.findOne({
|
|
offset: Math.floor(Math.random() * (await Videos.count())),
|
|
});
|
|
const Like3 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Like3?.setVideo) {
|
|
await Like3.setVideo(relatedVideo3);
|
|
}
|
|
}
|
|
|
|
async function associateLikeWithTeam() {
|
|
const relatedTeam0 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Like0 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Like0?.setTeam) {
|
|
await Like0.setTeam(relatedTeam0);
|
|
}
|
|
|
|
const relatedTeam1 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Like1 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Like1?.setTeam) {
|
|
await Like1.setTeam(relatedTeam1);
|
|
}
|
|
|
|
const relatedTeam2 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Like2 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Like2?.setTeam) {
|
|
await Like2.setTeam(relatedTeam2);
|
|
}
|
|
|
|
const relatedTeam3 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Like3 = await Likes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Like3?.setTeam) {
|
|
await Like3.setTeam(relatedTeam3);
|
|
}
|
|
}
|
|
|
|
async function associateMusicTrackWithTeam() {
|
|
const relatedTeam0 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const MusicTrack0 = await MusicTracks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (MusicTrack0?.setTeam) {
|
|
await MusicTrack0.setTeam(relatedTeam0);
|
|
}
|
|
|
|
const relatedTeam1 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const MusicTrack1 = await MusicTracks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (MusicTrack1?.setTeam) {
|
|
await MusicTrack1.setTeam(relatedTeam1);
|
|
}
|
|
|
|
const relatedTeam2 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const MusicTrack2 = await MusicTracks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (MusicTrack2?.setTeam) {
|
|
await MusicTrack2.setTeam(relatedTeam2);
|
|
}
|
|
|
|
const relatedTeam3 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const MusicTrack3 = await MusicTracks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (MusicTrack3?.setTeam) {
|
|
await MusicTrack3.setTeam(relatedTeam3);
|
|
}
|
|
}
|
|
|
|
async function associateVideoWithCreator() {
|
|
const relatedCreator0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Video0 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Video0?.setCreator) {
|
|
await Video0.setCreator(relatedCreator0);
|
|
}
|
|
|
|
const relatedCreator1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Video1 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Video1?.setCreator) {
|
|
await Video1.setCreator(relatedCreator1);
|
|
}
|
|
|
|
const relatedCreator2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Video2 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Video2?.setCreator) {
|
|
await Video2.setCreator(relatedCreator2);
|
|
}
|
|
|
|
const relatedCreator3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Video3 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Video3?.setCreator) {
|
|
await Video3.setCreator(relatedCreator3);
|
|
}
|
|
}
|
|
|
|
async function associateVideoWithTeam() {
|
|
const relatedTeam0 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Video0 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Video0?.setTeam) {
|
|
await Video0.setTeam(relatedTeam0);
|
|
}
|
|
|
|
const relatedTeam1 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Video1 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Video1?.setTeam) {
|
|
await Video1.setTeam(relatedTeam1);
|
|
}
|
|
|
|
const relatedTeam2 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Video2 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Video2?.setTeam) {
|
|
await Video2.setTeam(relatedTeam2);
|
|
}
|
|
|
|
const relatedTeam3 = await Teams.findOne({
|
|
offset: Math.floor(Math.random() * (await Teams.count())),
|
|
});
|
|
const Video3 = await Videos.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Video3?.setTeam) {
|
|
await Video3.setTeam(relatedTeam3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Comments.bulkCreate(CommentsData);
|
|
|
|
await Flags.bulkCreate(FlagsData);
|
|
|
|
await Likes.bulkCreate(LikesData);
|
|
|
|
await MusicTracks.bulkCreate(MusicTracksData);
|
|
|
|
await Videos.bulkCreate(VideosData);
|
|
|
|
await Teams.bulkCreate(TeamsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithTeam(),
|
|
|
|
await associateCommentWithUser(),
|
|
|
|
await associateCommentWithVideo(),
|
|
|
|
await associateCommentWithTeam(),
|
|
|
|
await associateFlagWithVideo(),
|
|
|
|
await associateFlagWithUser(),
|
|
|
|
await associateFlagWithTeam(),
|
|
|
|
await associateLikeWithUser(),
|
|
|
|
await associateLikeWithVideo(),
|
|
|
|
await associateLikeWithTeam(),
|
|
|
|
await associateMusicTrackWithTeam(),
|
|
|
|
await associateVideoWithCreator(),
|
|
|
|
await associateVideoWithTeam(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('comments', null, {});
|
|
|
|
await queryInterface.bulkDelete('flags', null, {});
|
|
|
|
await queryInterface.bulkDelete('likes', null, {});
|
|
|
|
await queryInterface.bulkDelete('music_tracks', null, {});
|
|
|
|
await queryInterface.bulkDelete('videos', null, {});
|
|
|
|
await queryInterface.bulkDelete('teams', null, {});
|
|
},
|
|
};
|