30911/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-22 06:30:14 +00:00

546 lines
13 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Contents = db.contents;
const Reactions = db.reactions;
const Rooms = db.rooms;
const Sponsors = db.sponsors;
const Organizations = db.organizations;
const ContentsData = [
{
content_type: 'video',
source_url: 'https://example.com/video1',
mood_tag: 'exciting',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
content_type: 'story',
source_url: 'https://example.com/story1',
mood_tag: 'nostalgic',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
content_type: 'tweet',
source_url: 'https://example.com/tweet1',
mood_tag: 'serious',
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ReactionsData = [
{
emoji: '😀',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
emoji: '❤️',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
emoji: '👍',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const RoomsData = [
{
theme: 'Tech Innovations',
start_time: new Date('2025-04-21T10:00:00Z'),
end_time: new Date('2025-04-21T12:00:00Z'),
privacy: 'private',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
theme: 'Art and Design',
start_time: new Date('2025-04-22T14:00:00Z'),
end_time: new Date('2025-04-22T16:00:00Z'),
privacy: 'private',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
theme: 'Music Lovers',
start_time: new Date('2025-04-23T18:00:00Z'),
end_time: new Date('2025-04-23T20:00:00Z'),
privacy: 'private',
// type code here for "relation_many" field
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const SponsorsData = [
{
name: 'TechCorp',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'ArtWorld',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'MusicFest',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const OrganizationsData = [
{
name: 'Arthur Eddington',
},
{
name: 'Leonard Euler',
},
{
name: 'Albert Einstein',
},
];
// Similar logic for "relation_many"
async function associateUserWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setOrganization) {
await User0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setOrganization) {
await User1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setOrganization) {
await User2.setOrganization(relatedOrganization2);
}
}
async function associateContentWithRoom() {
const relatedRoom0 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Content0 = await Contents.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Content0?.setRoom) {
await Content0.setRoom(relatedRoom0);
}
const relatedRoom1 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Content1 = await Contents.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Content1?.setRoom) {
await Content1.setRoom(relatedRoom1);
}
const relatedRoom2 = await Rooms.findOne({
offset: Math.floor(Math.random() * (await Rooms.count())),
});
const Content2 = await Contents.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Content2?.setRoom) {
await Content2.setRoom(relatedRoom2);
}
}
async function associateContentWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Content0 = await Contents.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Content0?.setOrganization) {
await Content0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Content1 = await Contents.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Content1?.setOrganization) {
await Content1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Content2 = await Contents.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Content2?.setOrganization) {
await Content2.setOrganization(relatedOrganization2);
}
}
async function associateReactionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Reaction0 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Reaction0?.setUser) {
await Reaction0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Reaction1 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Reaction1?.setUser) {
await Reaction1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Reaction2 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Reaction2?.setUser) {
await Reaction2.setUser(relatedUser2);
}
}
async function associateReactionWithContent() {
const relatedContent0 = await Contents.findOne({
offset: Math.floor(Math.random() * (await Contents.count())),
});
const Reaction0 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Reaction0?.setContent) {
await Reaction0.setContent(relatedContent0);
}
const relatedContent1 = await Contents.findOne({
offset: Math.floor(Math.random() * (await Contents.count())),
});
const Reaction1 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Reaction1?.setContent) {
await Reaction1.setContent(relatedContent1);
}
const relatedContent2 = await Contents.findOne({
offset: Math.floor(Math.random() * (await Contents.count())),
});
const Reaction2 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Reaction2?.setContent) {
await Reaction2.setContent(relatedContent2);
}
}
async function associateReactionWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Reaction0 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Reaction0?.setOrganization) {
await Reaction0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Reaction1 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Reaction1?.setOrganization) {
await Reaction1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Reaction2 = await Reactions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Reaction2?.setOrganization) {
await Reaction2.setOrganization(relatedOrganization2);
}
}
// Similar logic for "relation_many"
async function associateRoomWithCreator() {
const relatedCreator0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Room0 = await Rooms.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Room0?.setCreator) {
await Room0.setCreator(relatedCreator0);
}
const relatedCreator1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Room1 = await Rooms.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Room1?.setCreator) {
await Room1.setCreator(relatedCreator1);
}
const relatedCreator2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Room2 = await Rooms.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Room2?.setCreator) {
await Room2.setCreator(relatedCreator2);
}
}
async function associateRoomWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Room0 = await Rooms.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Room0?.setOrganization) {
await Room0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Room1 = await Rooms.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Room1?.setOrganization) {
await Room1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Room2 = await Rooms.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Room2?.setOrganization) {
await Room2.setOrganization(relatedOrganization2);
}
}
// Similar logic for "relation_many"
async function associateSponsorWithOrganization() {
const relatedOrganization0 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sponsor0 = await Sponsors.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Sponsor0?.setOrganization) {
await Sponsor0.setOrganization(relatedOrganization0);
}
const relatedOrganization1 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sponsor1 = await Sponsors.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Sponsor1?.setOrganization) {
await Sponsor1.setOrganization(relatedOrganization1);
}
const relatedOrganization2 = await Organizations.findOne({
offset: Math.floor(Math.random() * (await Organizations.count())),
});
const Sponsor2 = await Sponsors.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Sponsor2?.setOrganization) {
await Sponsor2.setOrganization(relatedOrganization2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Contents.bulkCreate(ContentsData);
await Reactions.bulkCreate(ReactionsData);
await Rooms.bulkCreate(RoomsData);
await Sponsors.bulkCreate(SponsorsData);
await Organizations.bulkCreate(OrganizationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithOrganization(),
await associateContentWithRoom(),
await associateContentWithOrganization(),
await associateReactionWithUser(),
await associateReactionWithContent(),
await associateReactionWithOrganization(),
// Similar logic for "relation_many"
await associateRoomWithCreator(),
await associateRoomWithOrganization(),
// Similar logic for "relation_many"
await associateSponsorWithOrganization(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('contents', null, {});
await queryInterface.bulkDelete('reactions', null, {});
await queryInterface.bulkDelete('rooms', null, {});
await queryInterface.bulkDelete('sponsors', null, {});
await queryInterface.bulkDelete('organizations', null, {});
},
};