430 lines
10 KiB
JavaScript
430 lines
10 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Communities = db.communities;
|
|
|
|
const Dreams = db.dreams;
|
|
|
|
const Interpretations = db.interpretations;
|
|
|
|
const Community = db.community;
|
|
|
|
const CommunitiesData = [
|
|
{
|
|
name: 'Dream Enthusiasts',
|
|
|
|
description:
|
|
'A community for those who love to share and interpret dreams.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Night Visionaries',
|
|
|
|
description: 'Exploring the depths of dreams and their meanings.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Dream Weavers',
|
|
|
|
description: 'Connecting dreamers and interpreters worldwide.',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const DreamsData = [
|
|
{
|
|
title: 'Flying Over Mountains',
|
|
|
|
content:
|
|
'I dreamt I was flying over a range of mountains, feeling free and exhilarated.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
posted_at: new Date('2023-10-01T08:30:00Z'),
|
|
},
|
|
|
|
{
|
|
title: 'Lost in a Maze',
|
|
|
|
content:
|
|
'I found myself in a maze, unable to find my way out, feeling anxious.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
posted_at: new Date('2023-10-02T09:00:00Z'),
|
|
},
|
|
|
|
{
|
|
title: 'Talking Animals',
|
|
|
|
content: 'Animals were talking to me, giving me advice on life.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
posted_at: new Date('2023-10-03T10:15:00Z'),
|
|
},
|
|
];
|
|
|
|
const InterpretationsData = [
|
|
{
|
|
content:
|
|
'Flying often represents freedom and a desire to rise above challenges.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
interpreted_at: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content:
|
|
'Being lost in a maze can symbolize feeling trapped or confused in life.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
interpreted_at: new Date('2023-10-02T09:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content:
|
|
'Talking animals might indicate a connection with nature or inner wisdom.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
interpreted_at: new Date('2023-10-03T10:45:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CommunityData = [
|
|
{
|
|
name: 'Joseph J. Thomson',
|
|
},
|
|
|
|
{
|
|
name: 'Jean Baptiste Lamarck',
|
|
},
|
|
|
|
{
|
|
name: 'Marie Curie',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithCommunity() {
|
|
const relatedCommunity0 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setCommunity) {
|
|
await User0.setCommunity(relatedCommunity0);
|
|
}
|
|
|
|
const relatedCommunity1 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setCommunity) {
|
|
await User1.setCommunity(relatedCommunity1);
|
|
}
|
|
|
|
const relatedCommunity2 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setCommunity) {
|
|
await User2.setCommunity(relatedCommunity2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCommunityWithCommunity() {
|
|
const relatedCommunity0 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const Community0 = await Communities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Community0?.setCommunity) {
|
|
await Community0.setCommunity(relatedCommunity0);
|
|
}
|
|
|
|
const relatedCommunity1 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const Community1 = await Communities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Community1?.setCommunity) {
|
|
await Community1.setCommunity(relatedCommunity1);
|
|
}
|
|
|
|
const relatedCommunity2 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const Community2 = await Communities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Community2?.setCommunity) {
|
|
await Community2.setCommunity(relatedCommunity2);
|
|
}
|
|
}
|
|
|
|
async function associateDreamWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Dream0 = await Dreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Dream0?.setUser) {
|
|
await Dream0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Dream1 = await Dreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Dream1?.setUser) {
|
|
await Dream1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Dream2 = await Dreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Dream2?.setUser) {
|
|
await Dream2.setUser(relatedUser2);
|
|
}
|
|
}
|
|
|
|
async function associateDreamWithCommunity() {
|
|
const relatedCommunity0 = await Communities.findOne({
|
|
offset: Math.floor(Math.random() * (await Communities.count())),
|
|
});
|
|
const Dream0 = await Dreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Dream0?.setCommunity) {
|
|
await Dream0.setCommunity(relatedCommunity0);
|
|
}
|
|
|
|
const relatedCommunity1 = await Communities.findOne({
|
|
offset: Math.floor(Math.random() * (await Communities.count())),
|
|
});
|
|
const Dream1 = await Dreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Dream1?.setCommunity) {
|
|
await Dream1.setCommunity(relatedCommunity1);
|
|
}
|
|
|
|
const relatedCommunity2 = await Communities.findOne({
|
|
offset: Math.floor(Math.random() * (await Communities.count())),
|
|
});
|
|
const Dream2 = await Dreams.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Dream2?.setCommunity) {
|
|
await Dream2.setCommunity(relatedCommunity2);
|
|
}
|
|
}
|
|
|
|
async function associateInterpretationWithDream() {
|
|
const relatedDream0 = await Dreams.findOne({
|
|
offset: Math.floor(Math.random() * (await Dreams.count())),
|
|
});
|
|
const Interpretation0 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Interpretation0?.setDream) {
|
|
await Interpretation0.setDream(relatedDream0);
|
|
}
|
|
|
|
const relatedDream1 = await Dreams.findOne({
|
|
offset: Math.floor(Math.random() * (await Dreams.count())),
|
|
});
|
|
const Interpretation1 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Interpretation1?.setDream) {
|
|
await Interpretation1.setDream(relatedDream1);
|
|
}
|
|
|
|
const relatedDream2 = await Dreams.findOne({
|
|
offset: Math.floor(Math.random() * (await Dreams.count())),
|
|
});
|
|
const Interpretation2 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Interpretation2?.setDream) {
|
|
await Interpretation2.setDream(relatedDream2);
|
|
}
|
|
}
|
|
|
|
async function associateInterpretationWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Interpretation0 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Interpretation0?.setUser) {
|
|
await Interpretation0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Interpretation1 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Interpretation1?.setUser) {
|
|
await Interpretation1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Interpretation2 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Interpretation2?.setUser) {
|
|
await Interpretation2.setUser(relatedUser2);
|
|
}
|
|
}
|
|
|
|
async function associateInterpretationWithCommunity() {
|
|
const relatedCommunity0 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const Interpretation0 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Interpretation0?.setCommunity) {
|
|
await Interpretation0.setCommunity(relatedCommunity0);
|
|
}
|
|
|
|
const relatedCommunity1 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const Interpretation1 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Interpretation1?.setCommunity) {
|
|
await Interpretation1.setCommunity(relatedCommunity1);
|
|
}
|
|
|
|
const relatedCommunity2 = await Community.findOne({
|
|
offset: Math.floor(Math.random() * (await Community.count())),
|
|
});
|
|
const Interpretation2 = await Interpretations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Interpretation2?.setCommunity) {
|
|
await Interpretation2.setCommunity(relatedCommunity2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Communities.bulkCreate(CommunitiesData);
|
|
|
|
await Dreams.bulkCreate(DreamsData);
|
|
|
|
await Interpretations.bulkCreate(InterpretationsData);
|
|
|
|
await Community.bulkCreate(CommunityData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithCommunity(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCommunityWithCommunity(),
|
|
|
|
await associateDreamWithUser(),
|
|
|
|
await associateDreamWithCommunity(),
|
|
|
|
await associateInterpretationWithDream(),
|
|
|
|
await associateInterpretationWithUser(),
|
|
|
|
await associateInterpretationWithCommunity(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('communities', null, {});
|
|
|
|
await queryInterface.bulkDelete('dreams', null, {});
|
|
|
|
await queryInterface.bulkDelete('interpretations', null, {});
|
|
|
|
await queryInterface.bulkDelete('community', null, {});
|
|
},
|
|
};
|