37872-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-01-27 11:54:41 +00:00

1464 lines
29 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Projects = db.projects;
const Tasks = db.tasks;
const Conversations = db.conversations;
const Messages = db.messages;
const Drafts = db.drafts;
const ProjectsData = [
{
"title": "Website Redesign",
"overview": "Complete redesign of the marketing website to improve conversion.",
"start_date": new Date('2026-01-05T09:00:00Z'),
"end_date": new Date('2026-04-30T17:00:00Z'),
// type code here for "relation_one" field
"status": "cancelled",
"budget": 45000.0,
},
{
"title": "Mobile App MVP",
"overview": "Build and ship an MVP for the new mobile experience.",
"start_date": new Date('2025-11-01T09:00:00Z'),
"end_date": new Date('2026-02-15T17:00:00Z'),
// type code here for "relation_one" field
"status": "planned",
"budget": 70000.0,
},
{
"title": "Analytics Pipeline",
"overview": "Implement data pipelines for product analytics and reporting.",
"start_date": new Date('2026-02-01T09:00:00Z'),
"end_date": new Date('2026-06-30T17:00:00Z'),
// type code here for "relation_one" field
"status": "planned",
"budget": 30000.0,
},
];
const TasksData = [
{
"title": "Create homepage wireframes",
"description": "Draft wireframes for the new homepage layout and content priorities.",
"status": "in_progress",
"priority": "low",
"due_date": new Date('2026-01-25T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Implement authentication endpoints",
"description": "Add login, registration and token refresh endpoints in the backend.",
"status": "blocked",
"priority": "urgent",
"due_date": new Date('2026-01-18T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"title": "Set up analytics ETL",
"description": "Create initial ETL jobs to collect user events into warehouse.",
"status": "done",
"priority": "low",
"due_date": new Date('2026-02-28T17:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ConversationsData = [
{
"title": "Scope alignment: Website Redesign",
"summary": "Discussion about final scope and deliverables for the website project.",
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "MVP feature prioritization",
"summary": "Decide which features to include in the mobile app MVP.",
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "Analytics requirements",
"summary": "List of events and metrics required by the analytics team.",
// type code here for "relation_one" field
// type code here for "relation_many" field
},
];
const MessagesData = [
{
"excerpt": "Initial wireframe draft attached",
"content": "Attached the first set of wireframes for homepage. Please review and comment.",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
"sent_on": new Date('2026-01-10T10:15:00Z'),
},
{
"excerpt": "Auth endpoints spec",
"content": "Added spec for auth endpoints to the repo. See endpoints.md for details.",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
"sent_on": new Date('2025-11-05T14:20:00Z'),
},
{
"excerpt": "Event list draft",
"content": "Drafted initial event list for analytics. Let me know if anything is missing.",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
"sent_on": new Date('2026-02-03T09:45:00Z'),
},
];
const DraftsData = [
{
"title": "Homepage hero content",
"body": "Draft copy and layout ideas for the homepage hero section.",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
"saved_on": new Date('2026-01-08T08:30:00Z'),
},
{
"title": "Auth API overview",
"body": "Notes on authentication flow, token lifecycle and session handling.",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
"saved_on": new Date('2025-11-03T12:00:00Z'),
},
{
"title": "Analytics event taxonomy",
"body": "Proposed taxonomy for event names and properties.",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "files" field
"saved_on": new Date('2026-02-10T09:00:00Z'),
},
];
// Similar logic for "relation_many"
async function associateProjectWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project0 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Project0?.setOwner)
{
await
Project0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project1 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Project1?.setOwner)
{
await
Project1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project2 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Project2?.setOwner)
{
await
Project2.
setOwner(relatedOwner2);
}
}
async function associateTaskWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Task0?.setProject)
{
await
Task0.
setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Task1?.setProject)
{
await
Task1.
setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Task2?.setProject)
{
await
Task2.
setProject(relatedProject2);
}
}
async function associateTaskWithAssignee() {
const relatedAssignee0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Task0?.setAssignee)
{
await
Task0.
setAssignee(relatedAssignee0);
}
const relatedAssignee1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Task1?.setAssignee)
{
await
Task1.
setAssignee(relatedAssignee1);
}
const relatedAssignee2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Task2?.setAssignee)
{
await
Task2.
setAssignee(relatedAssignee2);
}
}
async function associateConversationWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Conversation0 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Conversation0?.setProject)
{
await
Conversation0.
setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Conversation1 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Conversation1?.setProject)
{
await
Conversation1.
setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Conversation2 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Conversation2?.setProject)
{
await
Conversation2.
setProject(relatedProject2);
}
}
// Similar logic for "relation_many"
async function associateMessageWithAuthor() {
const relatedAuthor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setAuthor)
{
await
Message0.
setAuthor(relatedAuthor0);
}
const relatedAuthor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setAuthor)
{
await
Message1.
setAuthor(relatedAuthor1);
}
const relatedAuthor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setAuthor)
{
await
Message2.
setAuthor(relatedAuthor2);
}
}
async function associateMessageWithConversation() {
const relatedConversation0 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setConversation)
{
await
Message0.
setConversation(relatedConversation0);
}
const relatedConversation1 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setConversation)
{
await
Message1.
setConversation(relatedConversation1);
}
const relatedConversation2 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setConversation)
{
await
Message2.
setConversation(relatedConversation2);
}
}
async function associateDraftWithAuthor() {
const relatedAuthor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Draft0 = await Drafts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Draft0?.setAuthor)
{
await
Draft0.
setAuthor(relatedAuthor0);
}
const relatedAuthor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Draft1 = await Drafts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Draft1?.setAuthor)
{
await
Draft1.
setAuthor(relatedAuthor1);
}
const relatedAuthor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Draft2 = await Drafts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Draft2?.setAuthor)
{
await
Draft2.
setAuthor(relatedAuthor2);
}
}
async function associateDraftWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Draft0 = await Drafts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Draft0?.setProject)
{
await
Draft0.
setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Draft1 = await Drafts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Draft1?.setProject)
{
await
Draft1.
setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Draft2 = await Drafts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Draft2?.setProject)
{
await
Draft2.
setProject(relatedProject2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Projects.bulkCreate(ProjectsData);
await Tasks.bulkCreate(TasksData);
await Conversations.bulkCreate(ConversationsData);
await Messages.bulkCreate(MessagesData);
await Drafts.bulkCreate(DraftsData);
await Promise.all([
// Similar logic for "relation_many"
await associateProjectWithOwner(),
await associateTaskWithProject(),
await associateTaskWithAssignee(),
await associateConversationWithProject(),
// Similar logic for "relation_many"
await associateMessageWithAuthor(),
await associateMessageWithConversation(),
await associateDraftWithAuthor(),
await associateDraftWithProject(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('tasks', null, {});
await queryInterface.bulkDelete('conversations', null, {});
await queryInterface.bulkDelete('messages', null, {});
await queryInterface.bulkDelete('drafts', null, {});
},
};