587 lines
13 KiB
JavaScript
587 lines
13 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Forums = db.forums;
|
|
|
|
const Merchants = db.merchants;
|
|
|
|
const Notifications = db.notifications;
|
|
|
|
const Posts = db.posts;
|
|
|
|
const Residents = db.residents;
|
|
|
|
const Services = db.services;
|
|
|
|
const Subscribers = db.subscribers;
|
|
|
|
const ForumsData = [
|
|
{
|
|
title: 'Community Events',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
title: 'Maintenance Issues',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
title: 'Local Services',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
title: 'Neighborhood Watch',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const MerchantsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
profile_description: 'Expert plumber with 10 years experience.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
profile_description: 'Professional electrician for residential projects.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
profile_description: 'Certified HVAC technician.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
profile_description: 'Experienced painter and decorator.',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const NotificationsData = [
|
|
{
|
|
message: 'Welcome to our platform!',
|
|
|
|
sent_at: new Date('2023-10-01T09:00:00Z'),
|
|
},
|
|
|
|
{
|
|
message: 'Your file status has been updated.',
|
|
|
|
sent_at: new Date('2023-10-02T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
message: 'New service request received.',
|
|
|
|
sent_at: new Date('2023-10-03T11:00:00Z'),
|
|
},
|
|
|
|
{
|
|
message: 'Forum post created in your neighborhood.',
|
|
|
|
sent_at: new Date('2023-10-04T12:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const PostsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Join us for the annual block party!',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Looking for volunteers for the cleanup drive.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Elevator maintenance scheduled for next week.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Water supply will be interrupted on Friday.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ResidentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_many" field
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_many" field
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_many" field
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
// type code here for "relation_many" field
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const ServicesData = [
|
|
{
|
|
service_name: 'Plumbing',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
price: 50,
|
|
},
|
|
|
|
{
|
|
service_name: 'Electrical',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
price: 75,
|
|
},
|
|
|
|
{
|
|
service_name: 'HVAC',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
price: 100,
|
|
},
|
|
|
|
{
|
|
service_name: 'Painting',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
price: 60,
|
|
},
|
|
];
|
|
|
|
const SubscribersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
file_status: 'Pending',
|
|
|
|
last_update: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
file_status: 'Approved',
|
|
|
|
last_update: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
file_status: 'Rejected',
|
|
|
|
last_update: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
file_status: 'Pending',
|
|
|
|
last_update: new Date('2023-10-04T13:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateMerchantWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Merchant0 = await Merchants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Merchant0?.setUser) {
|
|
await Merchant0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Merchant1 = await Merchants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Merchant1?.setUser) {
|
|
await Merchant1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Merchant2 = await Merchants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Merchant2?.setUser) {
|
|
await Merchant2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Merchant3 = await Merchants.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Merchant3?.setUser) {
|
|
await Merchant3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associatePostWithForum() {
|
|
const relatedForum0 = await Forums.findOne({
|
|
offset: Math.floor(Math.random() * (await Forums.count())),
|
|
});
|
|
const Post0 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Post0?.setForum) {
|
|
await Post0.setForum(relatedForum0);
|
|
}
|
|
|
|
const relatedForum1 = await Forums.findOne({
|
|
offset: Math.floor(Math.random() * (await Forums.count())),
|
|
});
|
|
const Post1 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Post1?.setForum) {
|
|
await Post1.setForum(relatedForum1);
|
|
}
|
|
|
|
const relatedForum2 = await Forums.findOne({
|
|
offset: Math.floor(Math.random() * (await Forums.count())),
|
|
});
|
|
const Post2 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Post2?.setForum) {
|
|
await Post2.setForum(relatedForum2);
|
|
}
|
|
|
|
const relatedForum3 = await Forums.findOne({
|
|
offset: Math.floor(Math.random() * (await Forums.count())),
|
|
});
|
|
const Post3 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Post3?.setForum) {
|
|
await Post3.setForum(relatedForum3);
|
|
}
|
|
}
|
|
|
|
async function associatePostWithAuthor() {
|
|
const relatedAuthor0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post0 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Post0?.setAuthor) {
|
|
await Post0.setAuthor(relatedAuthor0);
|
|
}
|
|
|
|
const relatedAuthor1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post1 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Post1?.setAuthor) {
|
|
await Post1.setAuthor(relatedAuthor1);
|
|
}
|
|
|
|
const relatedAuthor2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post2 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Post2?.setAuthor) {
|
|
await Post2.setAuthor(relatedAuthor2);
|
|
}
|
|
|
|
const relatedAuthor3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Post3 = await Posts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Post3?.setAuthor) {
|
|
await Post3.setAuthor(relatedAuthor3);
|
|
}
|
|
}
|
|
|
|
async function associateResidentWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resident0 = await Residents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Resident0?.setUser) {
|
|
await Resident0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resident1 = await Residents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Resident1?.setUser) {
|
|
await Resident1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resident2 = await Residents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Resident2?.setUser) {
|
|
await Resident2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resident3 = await Residents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Resident3?.setUser) {
|
|
await Resident3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateServiceWithMerchant() {
|
|
const relatedMerchant0 = await Merchants.findOne({
|
|
offset: Math.floor(Math.random() * (await Merchants.count())),
|
|
});
|
|
const Service0 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Service0?.setMerchant) {
|
|
await Service0.setMerchant(relatedMerchant0);
|
|
}
|
|
|
|
const relatedMerchant1 = await Merchants.findOne({
|
|
offset: Math.floor(Math.random() * (await Merchants.count())),
|
|
});
|
|
const Service1 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Service1?.setMerchant) {
|
|
await Service1.setMerchant(relatedMerchant1);
|
|
}
|
|
|
|
const relatedMerchant2 = await Merchants.findOne({
|
|
offset: Math.floor(Math.random() * (await Merchants.count())),
|
|
});
|
|
const Service2 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Service2?.setMerchant) {
|
|
await Service2.setMerchant(relatedMerchant2);
|
|
}
|
|
|
|
const relatedMerchant3 = await Merchants.findOne({
|
|
offset: Math.floor(Math.random() * (await Merchants.count())),
|
|
});
|
|
const Service3 = await Services.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Service3?.setMerchant) {
|
|
await Service3.setMerchant(relatedMerchant3);
|
|
}
|
|
}
|
|
|
|
async function associateSubscriberWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscriber0 = await Subscribers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Subscriber0?.setUser) {
|
|
await Subscriber0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscriber1 = await Subscribers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Subscriber1?.setUser) {
|
|
await Subscriber1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscriber2 = await Subscribers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Subscriber2?.setUser) {
|
|
await Subscriber2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscriber3 = await Subscribers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Subscriber3?.setUser) {
|
|
await Subscriber3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Forums.bulkCreate(ForumsData);
|
|
|
|
await Merchants.bulkCreate(MerchantsData);
|
|
|
|
await Notifications.bulkCreate(NotificationsData);
|
|
|
|
await Posts.bulkCreate(PostsData);
|
|
|
|
await Residents.bulkCreate(ResidentsData);
|
|
|
|
await Services.bulkCreate(ServicesData);
|
|
|
|
await Subscribers.bulkCreate(SubscribersData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateMerchantWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associatePostWithForum(),
|
|
|
|
await associatePostWithAuthor(),
|
|
|
|
await associateResidentWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateServiceWithMerchant(),
|
|
|
|
await associateSubscriberWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('forums', null, {});
|
|
|
|
await queryInterface.bulkDelete('merchants', null, {});
|
|
|
|
await queryInterface.bulkDelete('notifications', null, {});
|
|
|
|
await queryInterface.bulkDelete('posts', null, {});
|
|
|
|
await queryInterface.bulkDelete('residents', null, {});
|
|
|
|
await queryInterface.bulkDelete('services', null, {});
|
|
|
|
await queryInterface.bulkDelete('subscribers', null, {});
|
|
},
|
|
};
|