639 lines
15 KiB
JavaScript
639 lines
15 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Feedbacks = db.feedbacks;
|
|
|
|
const Meetings = db.meetings;
|
|
|
|
const Profiles = db.profiles;
|
|
|
|
const Tenant = db.tenant;
|
|
|
|
const FeedbacksData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
response: 'no',
|
|
|
|
comments: 'Great conversation, looking forward to more.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
response: 'yes',
|
|
|
|
comments: 'Not a good match, different interests.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
response: 'no',
|
|
|
|
comments: 'Enjoyed the meeting, very pleasant.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
response: 'yes',
|
|
|
|
comments: 'Not compatible, different goals.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MeetingsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_time: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
location: 'Central Coffee Shop',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_time: new Date('2023-11-02T14:00:00Z'),
|
|
|
|
location: 'Downtown Cafe',
|
|
|
|
status: 'accepted',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_time: new Date('2023-11-03T16:00:00Z'),
|
|
|
|
location: 'City Park Cafe',
|
|
|
|
status: 'pending',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
scheduled_time: new Date('2023-11-04T11:00:00Z'),
|
|
|
|
location: 'Riverside Bistro',
|
|
|
|
status: 'rejected',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProfilesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
hobbies: 'Reading, Traveling, Cooking',
|
|
|
|
visibility: 'private',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
hobbies: 'Photography, Hiking, Music',
|
|
|
|
visibility: 'private',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
hobbies: 'Gardening, Painting, Writing',
|
|
|
|
visibility: 'private',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
hobbies: 'Cycling, Yoga, Movies',
|
|
|
|
visibility: 'public',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TenantData = [
|
|
{
|
|
name: 'Edward Teller',
|
|
},
|
|
|
|
{
|
|
name: 'Max Born',
|
|
},
|
|
|
|
{
|
|
name: 'Theodosius Dobzhansky',
|
|
},
|
|
|
|
{
|
|
name: 'Ernst Haeckel',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithTenant() {
|
|
const relatedTenant0 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setTenant) {
|
|
await User0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setTenant) {
|
|
await User1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setTenant) {
|
|
await User2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setTenant) {
|
|
await User3.setTenant(relatedTenant3);
|
|
}
|
|
}
|
|
|
|
async function associateFeedbackWithMeeting() {
|
|
const relatedMeeting0 = await Meetings.findOne({
|
|
offset: Math.floor(Math.random() * (await Meetings.count())),
|
|
});
|
|
const Feedback0 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Feedback0?.setMeeting) {
|
|
await Feedback0.setMeeting(relatedMeeting0);
|
|
}
|
|
|
|
const relatedMeeting1 = await Meetings.findOne({
|
|
offset: Math.floor(Math.random() * (await Meetings.count())),
|
|
});
|
|
const Feedback1 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Feedback1?.setMeeting) {
|
|
await Feedback1.setMeeting(relatedMeeting1);
|
|
}
|
|
|
|
const relatedMeeting2 = await Meetings.findOne({
|
|
offset: Math.floor(Math.random() * (await Meetings.count())),
|
|
});
|
|
const Feedback2 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Feedback2?.setMeeting) {
|
|
await Feedback2.setMeeting(relatedMeeting2);
|
|
}
|
|
|
|
const relatedMeeting3 = await Meetings.findOne({
|
|
offset: Math.floor(Math.random() * (await Meetings.count())),
|
|
});
|
|
const Feedback3 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Feedback3?.setMeeting) {
|
|
await Feedback3.setMeeting(relatedMeeting3);
|
|
}
|
|
}
|
|
|
|
async function associateFeedbackWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Feedback0 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Feedback0?.setUser) {
|
|
await Feedback0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Feedback1 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Feedback1?.setUser) {
|
|
await Feedback1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Feedback2 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Feedback2?.setUser) {
|
|
await Feedback2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Feedback3 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Feedback3?.setUser) {
|
|
await Feedback3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associateFeedbackWithTenant() {
|
|
const relatedTenant0 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Feedback0 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Feedback0?.setTenant) {
|
|
await Feedback0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Feedback1 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Feedback1?.setTenant) {
|
|
await Feedback1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Feedback2 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Feedback2?.setTenant) {
|
|
await Feedback2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Feedback3 = await Feedbacks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Feedback3?.setTenant) {
|
|
await Feedback3.setTenant(relatedTenant3);
|
|
}
|
|
}
|
|
|
|
async function associateMeetingWithRequester() {
|
|
const relatedRequester0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting0 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Meeting0?.setRequester) {
|
|
await Meeting0.setRequester(relatedRequester0);
|
|
}
|
|
|
|
const relatedRequester1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting1 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Meeting1?.setRequester) {
|
|
await Meeting1.setRequester(relatedRequester1);
|
|
}
|
|
|
|
const relatedRequester2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting2 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Meeting2?.setRequester) {
|
|
await Meeting2.setRequester(relatedRequester2);
|
|
}
|
|
|
|
const relatedRequester3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting3 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Meeting3?.setRequester) {
|
|
await Meeting3.setRequester(relatedRequester3);
|
|
}
|
|
}
|
|
|
|
async function associateMeetingWithPartner() {
|
|
const relatedPartner0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting0 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Meeting0?.setPartner) {
|
|
await Meeting0.setPartner(relatedPartner0);
|
|
}
|
|
|
|
const relatedPartner1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting1 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Meeting1?.setPartner) {
|
|
await Meeting1.setPartner(relatedPartner1);
|
|
}
|
|
|
|
const relatedPartner2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting2 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Meeting2?.setPartner) {
|
|
await Meeting2.setPartner(relatedPartner2);
|
|
}
|
|
|
|
const relatedPartner3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Meeting3 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Meeting3?.setPartner) {
|
|
await Meeting3.setPartner(relatedPartner3);
|
|
}
|
|
}
|
|
|
|
async function associateMeetingWithTenant() {
|
|
const relatedTenant0 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Meeting0 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Meeting0?.setTenant) {
|
|
await Meeting0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Meeting1 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Meeting1?.setTenant) {
|
|
await Meeting1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Meeting2 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Meeting2?.setTenant) {
|
|
await Meeting2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Meeting3 = await Meetings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Meeting3?.setTenant) {
|
|
await Meeting3.setTenant(relatedTenant3);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
async function associateProfileWithTenant() {
|
|
const relatedTenant0 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Profile0 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Profile0?.setTenant) {
|
|
await Profile0.setTenant(relatedTenant0);
|
|
}
|
|
|
|
const relatedTenant1 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Profile1 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Profile1?.setTenant) {
|
|
await Profile1.setTenant(relatedTenant1);
|
|
}
|
|
|
|
const relatedTenant2 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Profile2 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Profile2?.setTenant) {
|
|
await Profile2.setTenant(relatedTenant2);
|
|
}
|
|
|
|
const relatedTenant3 = await Tenant.findOne({
|
|
offset: Math.floor(Math.random() * (await Tenant.count())),
|
|
});
|
|
const Profile3 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Profile3?.setTenant) {
|
|
await Profile3.setTenant(relatedTenant3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Feedbacks.bulkCreate(FeedbacksData);
|
|
|
|
await Meetings.bulkCreate(MeetingsData);
|
|
|
|
await Profiles.bulkCreate(ProfilesData);
|
|
|
|
await Tenant.bulkCreate(TenantData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithTenant(),
|
|
|
|
await associateFeedbackWithMeeting(),
|
|
|
|
await associateFeedbackWithUser(),
|
|
|
|
await associateFeedbackWithTenant(),
|
|
|
|
await associateMeetingWithRequester(),
|
|
|
|
await associateMeetingWithPartner(),
|
|
|
|
await associateMeetingWithTenant(),
|
|
|
|
await associateProfileWithUser(),
|
|
|
|
await associateProfileWithTenant(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('feedbacks', null, {});
|
|
|
|
await queryInterface.bulkDelete('meetings', null, {});
|
|
|
|
await queryInterface.bulkDelete('profiles', null, {});
|
|
|
|
await queryInterface.bulkDelete('tenant', null, {});
|
|
},
|
|
};
|