1071 lines
24 KiB
JavaScript
1071 lines
24 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Livestreams = db.livestreams;
|
|
|
|
const Comments = db.comments;
|
|
|
|
const Messages = db.messages;
|
|
|
|
const Posts = db.posts;
|
|
|
|
const Products = db.products;
|
|
|
|
const Nests = db.nests;
|
|
|
|
const Settings = db.settings;
|
|
|
|
const LivestreamsData = [
|
|
{
|
|
title: 'AI in 2023',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-10-06T10:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-06T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Digital Art Workshop',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-10-07T12:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-07T13:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Gaming Tournament',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-10-08T14:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-08T16:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Music Jam Session',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-10-09T16:00:00Z'),
|
|
|
|
end_time: new Date('2023-10-09T17:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CommentsData = [
|
|
{
|
|
content: 'Great insights on AI!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
commented_at: new Date('2023-10-01T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Love these art tips!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
commented_at: new Date('2023-10-02T13:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Thanks for the strategies!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
commented_at: new Date('2023-10-03T15:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Awesome music list!',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
commented_at: new Date('2023-10-04T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MessagesData = [
|
|
{
|
|
content: 'Hey, are you joining the tech meetup?',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sent_at: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: "Yes, I'll be there!",
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sent_at: new Date('2023-10-01T09:05:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Can you share the art resources?',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sent_at: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: "Sure, I'll send them over.",
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
sent_at: new Date('2023-10-02T11:10:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PostsData = [
|
|
{
|
|
title: 'Latest Tech Trends',
|
|
|
|
content: 'Exploring the latest trends in AI and machine learning.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
published_at: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Digital Art Tips',
|
|
|
|
content: 'Tips and tricks for creating stunning digital art.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
published_at: new Date('2023-10-02T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Gaming Strategies',
|
|
|
|
content: 'Top strategies for winning in competitive games.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
published_at: new Date('2023-10-03T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'New Music Releases',
|
|
|
|
content: 'Check out the latest music releases this week.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
published_at: new Date('2023-10-04T16:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Tech Gadget',
|
|
|
|
price: 99.99,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Art Supplies Kit',
|
|
|
|
price: 49.99,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Gaming Headset',
|
|
|
|
price: 79.99,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Music Album',
|
|
|
|
price: 14.99,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const NestsData = [
|
|
{
|
|
name: 'Tech Enthusiasts',
|
|
},
|
|
|
|
{
|
|
name: 'Art & Design',
|
|
},
|
|
|
|
{
|
|
name: 'Gaming Hub',
|
|
},
|
|
|
|
{
|
|
name: 'Music Lovers',
|
|
},
|
|
];
|
|
|
|
const SettingsData = [
|
|
{
|
|
// 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
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setNest) {
|
|
await User0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setNest) {
|
|
await User1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setNest) {
|
|
await User2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setNest) {
|
|
await User3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
async function associateLivestreamWithHost() {
|
|
const relatedHost0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Livestream0 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Livestream0?.setHost) {
|
|
await Livestream0.setHost(relatedHost0);
|
|
}
|
|
|
|
const relatedHost1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Livestream1 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Livestream1?.setHost) {
|
|
await Livestream1.setHost(relatedHost1);
|
|
}
|
|
|
|
const relatedHost2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Livestream2 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Livestream2?.setHost) {
|
|
await Livestream2.setHost(relatedHost2);
|
|
}
|
|
|
|
const relatedHost3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Livestream3 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Livestream3?.setHost) {
|
|
await Livestream3.setHost(relatedHost3);
|
|
}
|
|
}
|
|
|
|
async function associateLivestreamWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Livestream0 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Livestream0?.setNest) {
|
|
await Livestream0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Livestream1 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Livestream1?.setNest) {
|
|
await Livestream1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Livestream2 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Livestream2?.setNest) {
|
|
await Livestream2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Livestream3 = await Livestreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Livestream3?.setNest) {
|
|
await Livestream3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
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 associateCommentWithPost() {
|
|
const relatedPost0 = await Posts.findOne({
|
|
offset: Math.floor(Math.random() * (await Posts.count())),
|
|
});
|
|
const Comment0 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Comment0?.setPost) {
|
|
await Comment0.setPost(relatedPost0);
|
|
}
|
|
|
|
const relatedPost1 = await Posts.findOne({
|
|
offset: Math.floor(Math.random() * (await Posts.count())),
|
|
});
|
|
const Comment1 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Comment1?.setPost) {
|
|
await Comment1.setPost(relatedPost1);
|
|
}
|
|
|
|
const relatedPost2 = await Posts.findOne({
|
|
offset: Math.floor(Math.random() * (await Posts.count())),
|
|
});
|
|
const Comment2 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Comment2?.setPost) {
|
|
await Comment2.setPost(relatedPost2);
|
|
}
|
|
|
|
const relatedPost3 = await Posts.findOne({
|
|
offset: Math.floor(Math.random() * (await Posts.count())),
|
|
});
|
|
const Comment3 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Comment3?.setPost) {
|
|
await Comment3.setPost(relatedPost3);
|
|
}
|
|
}
|
|
|
|
async function associateCommentWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Comment0 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Comment0?.setNest) {
|
|
await Comment0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Comment1 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Comment1?.setNest) {
|
|
await Comment1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Comment2 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Comment2?.setNest) {
|
|
await Comment2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Comment3 = await Comments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Comment3?.setNest) {
|
|
await Comment3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithSender() {
|
|
const relatedSender0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setSender) {
|
|
await Message0.setSender(relatedSender0);
|
|
}
|
|
|
|
const relatedSender1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setSender) {
|
|
await Message1.setSender(relatedSender1);
|
|
}
|
|
|
|
const relatedSender2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setSender) {
|
|
await Message2.setSender(relatedSender2);
|
|
}
|
|
|
|
const relatedSender3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setSender) {
|
|
await Message3.setSender(relatedSender3);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithReceiver() {
|
|
const relatedReceiver0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setReceiver) {
|
|
await Message0.setReceiver(relatedReceiver0);
|
|
}
|
|
|
|
const relatedReceiver1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setReceiver) {
|
|
await Message1.setReceiver(relatedReceiver1);
|
|
}
|
|
|
|
const relatedReceiver2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setReceiver) {
|
|
await Message2.setReceiver(relatedReceiver2);
|
|
}
|
|
|
|
const relatedReceiver3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setReceiver) {
|
|
await Message3.setReceiver(relatedReceiver3);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setNest) {
|
|
await Message0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setNest) {
|
|
await Message1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setNest) {
|
|
await Message2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setNest) {
|
|
await Message3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
async function associatePostWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post0 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Post0?.setUser) {
|
|
await Post0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post1 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Post1?.setUser) {
|
|
await Post1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post2 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Post2?.setUser) {
|
|
await Post2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post3 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Post3?.setUser) {
|
|
await Post3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associatePostWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post0 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Post0?.setNest) {
|
|
await Post0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post1 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Post1?.setNest) {
|
|
await Post1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post2 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Post2?.setNest) {
|
|
await Post2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post3 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Post3?.setNest) {
|
|
await Post3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
async function associatePostWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post0 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Post0?.setNest) {
|
|
await Post0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post1 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Post1?.setNest) {
|
|
await Post1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post2 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Post2?.setNest) {
|
|
await Post2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Post3 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Post3?.setNest) {
|
|
await Post3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
async function associateProductWithSeller() {
|
|
const relatedSeller0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setSeller) {
|
|
await Product0.setSeller(relatedSeller0);
|
|
}
|
|
|
|
const relatedSeller1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setSeller) {
|
|
await Product1.setSeller(relatedSeller1);
|
|
}
|
|
|
|
const relatedSeller2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setSeller) {
|
|
await Product2.setSeller(relatedSeller2);
|
|
}
|
|
|
|
const relatedSeller3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setSeller) {
|
|
await Product3.setSeller(relatedSeller3);
|
|
}
|
|
}
|
|
|
|
async function associateProductWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setNest) {
|
|
await Product0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setNest) {
|
|
await Product1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setNest) {
|
|
await Product2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setNest) {
|
|
await Product3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
async function associateSettingWithNest() {
|
|
const relatedNest0 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Setting0 = await Settings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Setting0?.setNest) {
|
|
await Setting0.setNest(relatedNest0);
|
|
}
|
|
|
|
const relatedNest1 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Setting1 = await Settings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Setting1?.setNest) {
|
|
await Setting1.setNest(relatedNest1);
|
|
}
|
|
|
|
const relatedNest2 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Setting2 = await Settings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Setting2?.setNest) {
|
|
await Setting2.setNest(relatedNest2);
|
|
}
|
|
|
|
const relatedNest3 = await Nests.findOne({
|
|
offset: Math.floor(Math.random() * (await Nests.count())),
|
|
});
|
|
const Setting3 = await Settings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Setting3?.setNest) {
|
|
await Setting3.setNest(relatedNest3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Livestreams.bulkCreate(LivestreamsData);
|
|
|
|
await Comments.bulkCreate(CommentsData);
|
|
|
|
await Messages.bulkCreate(MessagesData);
|
|
|
|
await Posts.bulkCreate(PostsData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Nests.bulkCreate(NestsData);
|
|
|
|
await Settings.bulkCreate(SettingsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithNest(),
|
|
|
|
await associateLivestreamWithHost(),
|
|
|
|
await associateLivestreamWithNest(),
|
|
|
|
await associateCommentWithUser(),
|
|
|
|
await associateCommentWithPost(),
|
|
|
|
await associateCommentWithNest(),
|
|
|
|
await associateMessageWithSender(),
|
|
|
|
await associateMessageWithReceiver(),
|
|
|
|
await associateMessageWithNest(),
|
|
|
|
await associatePostWithUser(),
|
|
|
|
await associatePostWithNest(),
|
|
|
|
await associatePostWithNest(),
|
|
|
|
await associateProductWithSeller(),
|
|
|
|
await associateProductWithNest(),
|
|
|
|
await associateSettingWithNest(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('livestreams', null, {});
|
|
|
|
await queryInterface.bulkDelete('comments', null, {});
|
|
|
|
await queryInterface.bulkDelete('messages', null, {});
|
|
|
|
await queryInterface.bulkDelete('posts', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
await queryInterface.bulkDelete('nests', null, {});
|
|
|
|
await queryInterface.bulkDelete('settings', null, {});
|
|
},
|
|
};
|