32609/backend/src/db/seeders/20231127130745-sample-data.js
2025-07-03 18:13:47 +00:00

564 lines
12 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Analytics = db.analytics;
const Events = db.events;
const Messages = db.messages;
const Profiles = db.profiles;
const Subscriptions = db.subscriptions;
const AnalyticsData = [
{
user_count: 500,
engagement: 75,
top_interests: 'sola scriptura, Calvinism',
},
{
user_count: 450,
engagement: 60,
top_interests: 'church history, TULIP',
},
{
user_count: 600,
engagement: 80,
top_interests: 'New Believer, Reformed',
},
{
user_count: 550,
engagement: 70,
top_interests: 'Content Creator, Reformed',
},
{
user_count: 520,
engagement: 65,
top_interests: 'sola fide, Reformed',
},
];
const EventsData = [
{
title: 'Reformed Theology Webinar',
description:
'An online event discussing the fundamentals of Reformed theology.',
start_date: new Date('2023-11-10T18:00:00Z'),
end_date: new Date('2023-11-10T20:00:00Z'),
// type code here for "relation_many" field
},
{
title: 'Church History Meetup',
description: 'A gathering to explore significant events in church history.',
start_date: new Date('2023-11-15T17:00:00Z'),
end_date: new Date('2023-11-15T19:00:00Z'),
// type code here for "relation_many" field
},
{
title: 'Calvinism Study Group',
description: 'A study group focused on the teachings of Calvinism.',
start_date: new Date('2023-11-20T19:00:00Z'),
end_date: new Date('2023-11-20T21:00:00Z'),
// type code here for "relation_many" field
},
{
title: 'Sola Scriptura Discussion',
description: 'A discussion on the principle of Sola Scriptura.',
start_date: new Date('2023-11-25T18:30:00Z'),
end_date: new Date('2023-11-25T20:30:00Z'),
// type code here for "relation_many" field
},
{
title: 'TULIP Seminar',
description: 'An in-depth seminar on the TULIP doctrines.',
start_date: new Date('2023-11-30T17:30:00Z'),
end_date: new Date('2023-11-30T19:30:00Z'),
// type code here for "relation_many" field
},
];
const MessagesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'Hello, welcome to the network!',
sent_at: new Date('2023-10-01T10:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'Thanks for connecting!',
sent_at: new Date('2023-10-01T11:00:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'Looking forward to learning more.',
sent_at: new Date('2023-10-02T09:30:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: 'Check out my latest post!',
sent_at: new Date('2023-10-03T14:45:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
content: "Let's discuss sola fide.",
sent_at: new Date('2023-10-04T16:20:00Z'),
},
];
const ProfilesData = [
{
// type code here for "relation_one" field
bio: 'Passionate about Reformed theology and community building.',
// type code here for "images" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
bio: 'Exploring the depths of church history.',
// type code here for "images" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
bio: 'New to Reformed theology, eager to learn.',
// type code here for "images" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
bio: 'Content creator focused on Reformed teachings.',
// type code here for "images" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
// type code here for "relation_one" field
bio: 'Dedicated to spreading Reformed theology.',
// type code here for "images" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
];
const SubscriptionsData = [
{
// type code here for "relation_one" field
status: 'Active',
start_date: new Date('2023-09-01T00:00:00Z'),
end_date: new Date('2024-09-01T00:00:00Z'),
},
{
// type code here for "relation_one" field
status: 'Active',
start_date: new Date('2022-09-01T00:00:00Z'),
end_date: new Date('2023-09-01T00:00:00Z'),
},
{
// type code here for "relation_one" field
status: 'Active',
start_date: new Date('2023-10-01T00:00:00Z'),
end_date: new Date('2024-10-01T00:00:00Z'),
},
{
// type code here for "relation_one" field
status: 'Expired',
start_date: new Date('2023-08-15T00:00:00Z'),
end_date: new Date('2024-08-15T00:00:00Z'),
},
{
// type code here for "relation_one" field
status: 'Active',
start_date: new Date('2023-07-01T00:00:00Z'),
end_date: new Date('2024-07-01T00:00:00Z'),
},
];
// Similar logic for "relation_many"
// Similar logic for "relation_many"
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);
}
const relatedSender4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message4 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Message4?.setSender) {
await Message4.setSender(relatedSender4);
}
}
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);
}
const relatedReceiver4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message4 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Message4?.setReceiver) {
await Message4.setReceiver(relatedReceiver4);
}
}
async function associateProfileWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Profile0 = await Profiles.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Profile0?.setUser) {
await Profile0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Profile1 = await Profiles.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Profile1?.setUser) {
await Profile1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Profile2 = await Profiles.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Profile2?.setUser) {
await Profile2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Profile3 = await Profiles.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Profile3?.setUser) {
await Profile3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Profile4 = await Profiles.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Profile4?.setUser) {
await Profile4.setUser(relatedUser4);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateSubscriptionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Subscription0 = await Subscriptions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Subscription0?.setUser) {
await Subscription0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Subscription1 = await Subscriptions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Subscription1?.setUser) {
await Subscription1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Subscription2 = await Subscriptions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Subscription2?.setUser) {
await Subscription2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Subscription3 = await Subscriptions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Subscription3?.setUser) {
await Subscription3.setUser(relatedUser3);
}
const relatedUser4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Subscription4 = await Subscriptions.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Subscription4?.setUser) {
await Subscription4.setUser(relatedUser4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Analytics.bulkCreate(AnalyticsData);
await Events.bulkCreate(EventsData);
await Messages.bulkCreate(MessagesData);
await Profiles.bulkCreate(ProfilesData);
await Subscriptions.bulkCreate(SubscriptionsData);
await Promise.all([
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateMessageWithSender(),
await associateMessageWithReceiver(),
await associateProfileWithUser(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateSubscriptionWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('analytics', null, {});
await queryInterface.bulkDelete('events', null, {});
await queryInterface.bulkDelete('messages', null, {});
await queryInterface.bulkDelete('profiles', null, {});
await queryInterface.bulkDelete('subscriptions', null, {});
},
};