39378-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-30 01:52:20 +00:00

3615 lines
74 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Projects = db.projects;
const Tasks = db.tasks;
const Comments = db.comments;
const Attachments = db.attachments;
const Conversations = db.conversations;
const Messages = db.messages;
const Documents = db.documents;
const DocumentFiles = db.document_files;
const ProjectsData = [
{
"name": "Atlas Launch",
"slug": "atlas-launch",
"summary": "Project planning and delivery for Atlas Launch.",
"description": "Central workspace for planning, tracking tasks, and publishing project documentation.",
"status": "idea",
"start_at": new Date('2026-03-01T09:00:00Z'),
"end_at": new Date('2026-04-30T17:00:00Z'),
"is_public": false,
"repository_url": "https://github.com/newwebproject/atlas-launch",
"website_url": "https://atlas.newwebproject.example",
// type code here for "images" 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_many" field
// type code here for "relation_many" field
},
{
"name": "Nova Website Refresh",
"slug": "nova-website-refresh",
"summary": "Refresh marketing site content and visuals.",
"description": "Update branding assets, improve pages performance, and ensure accessibility compliance.",
"status": "on_hold",
"start_at": new Date('2026-03-10T09:00:00Z'),
"end_at": new Date('2026-05-15T17:00:00Z'),
"is_public": true,
"repository_url": "https://github.com/newwebproject/nova-website",
"website_url": "https://nova.newwebproject.example",
// type code here for "images" 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_many" field
// type code here for "relation_many" field
},
{
"name": "Orion API Stabilization",
"slug": "orion-api-stabilization",
"summary": "Improve reliability and observability for Orion API.",
"description": "Reduce error rates, add tracing, and improve CI coverage.",
"status": "on_hold",
"start_at": new Date('2026-02-15T09:00:00Z'),
"end_at": new Date('2026-04-01T17:00:00Z'),
"is_public": false,
"repository_url": "https://github.com/newwebproject/orion-api",
"website_url": "https://orion.newwebproject.example",
// type code here for "images" 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_many" field
// type code here for "relation_many" field
},
{
"name": "Helios Support Portal",
"slug": "helios-support-portal",
"summary": "Internal support portal for ticket triage.",
"description": "Provide a lightweight portal for requests, knowledge base articles, and status updates.",
"status": "archived",
"start_at": new Date('2026-04-01T09:00:00Z'),
"end_at": new Date('2026-06-30T17:00:00Z'),
"is_public": true,
"repository_url": "https://github.com/newwebproject/helios-portal",
"website_url": "https://helios.newwebproject.example",
// type code here for "images" 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_many" field
// type code here for "relation_many" field
},
];
const TasksData = [
{
"title": "Set up project repository and CI",
"details": "Initialize repository, configure linting, tests, and CI pipeline.",
"status": "todo",
"priority": "urgent",
"due_at": new Date('2026-03-28T17:00:00Z'),
"started_at": new Date('2026-03-15T10:00:00Z'),
"completed_at": new Date('2026-03-30T17:00:00Z'),
"estimate_points": 5,
"progress_percent": 70.0,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
"title": "Define MVP scope and milestones",
"details": "Document core features, success metrics, and milestone dates.",
"status": "backlog",
"priority": "urgent",
"due_at": new Date('2026-03-26T17:00:00Z'),
"started_at": new Date('2026-03-12T09:30:00Z'),
"completed_at": new Date('2026-03-27T16:00:00Z'),
"estimate_points": 3,
"progress_percent": 90.0,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
"title": "Design database schema for tasks and docs",
"details": "Create entities and relations for tasks, comments, attachments, and documents.",
"status": "todo",
"priority": "urgent",
"due_at": new Date('2026-03-20T17:00:00Z'),
"started_at": new Date('2026-03-10T13:00:00Z'),
"completed_at": new Date('2026-03-18T15:30:00Z'),
"estimate_points": 8,
"progress_percent": 100.0,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
{
"title": "Create content inventory",
"details": "List pages, owners, and required updates for the refresh.",
"status": "review",
"priority": "low",
"due_at": new Date('2026-03-29T17:00:00Z'),
"started_at": new Date('2026-03-20T09:00:00Z'),
"completed_at": new Date('2026-04-02T12:00:00Z'),
"estimate_points": 2,
"progress_percent": 20.0,
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
},
];
const CommentsData = [
{
"body": "CI baseline looks good. Please add a nightly build.",
"posted_at": new Date('2026-03-16T11:15:00Z'),
"is_edited": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"body": "Added lint and unit test steps. Will follow up on nightly schedule.",
"posted_at": new Date('2026-03-16T13:40:00Z'),
"is_edited": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"body": "MVP scope draft is ready for review in the project doc.",
"posted_at": new Date('2026-03-14T10:05:00Z'),
"is_edited": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"body": "Schema proposal approved. Please include attachments and doc files linkage.",
"posted_at": new Date('2026-03-18T16:10:00Z'),
"is_edited": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const AttachmentsData = [
{
"name": "ci-pipeline.yml",
// type code here for "files" field
// type code here for "images" field
"content_type": "text/yaml",
"size_bytes": 18432,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "schema-diagram.png",
// type code here for "files" field
// type code here for "images" field
"content_type": "image/png",
"size_bytes": 245760,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "a11y-audit-notes.pdf",
// type code here for "files" field
// type code here for "images" field
"content_type": "application/pdf",
"size_bytes": 512000,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "docs-taxonomy.xlsx",
// type code here for "files" field
// type code here for "images" field
"content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"size_bytes": 98304,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const ConversationsData = [
{
"title": "Atlas Launch Planning",
"kind": "planning",
"opened_at": new Date('2026-03-10T09:00:00Z'),
"closed_at": new Date('2026-04-15T17:00:00Z'),
"is_locked": false,
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "Nova Refresh Coordination",
"kind": "planning",
"opened_at": new Date('2026-03-12T10:00:00Z'),
"closed_at": new Date('2026-04-30T17:00:00Z'),
"is_locked": true,
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "Orion Reliability Updates",
"kind": "general",
"opened_at": new Date('2026-03-18T09:30:00Z'),
"closed_at": new Date('2026-04-20T17:00:00Z'),
"is_locked": false,
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "Helios Portal Intake",
"kind": "development",
"opened_at": new Date('2026-04-02T09:00:00Z'),
"closed_at": new Date('2026-05-15T17:00:00Z'),
"is_locked": false,
// type code here for "relation_one" field
// type code here for "relation_many" field
},
];
const MessagesData = [
{
"content": "Kickoff notes: align on MVP and timeline. Next step is milestone draft.",
"sent_at": new Date('2026-03-10T09:15:00Z'),
"is_system": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"content": "I will publish the milestone draft by Thursday and link it in Documents.",
"sent_at": new Date('2026-03-10T10:05:00Z'),
"is_system": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"content": "Please add page owners to the content inventory sheet by Friday.",
"sent_at": new Date('2026-03-12T10:10:00Z'),
"is_system": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"content": "Acknowledged. I will also flag any accessibility concerns early.",
"sent_at": new Date('2026-03-12T10:22:00Z'),
"is_system": true,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const DocumentsData = [
{
"title": "Atlas MVP Scope",
"content": "This document defines the MVP scope, success metrics, and delivery milestones for Atlas Launch.",
"visibility": "project",
"published_at": new Date('2026-03-14T12:00:00Z'),
"last_reviewed_at": new Date('2026-03-20T15:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "Nova Content Inventory",
"content": "Inventory of pages, owners, and required updates for the website refresh.",
"visibility": "public",
"published_at": new Date('2026-03-16T10:00:00Z'),
"last_reviewed_at": new Date('2026-03-22T11:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "Orion Observability Plan",
"content": "Plan to add tracing, dashboards, alerts, and error budget reporting.",
"visibility": "project",
"published_at": new Date('2026-03-19T13:00:00Z'),
"last_reviewed_at": new Date('2026-03-25T09:30:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
},
{
"title": "Helios Requirements Draft",
"content": "Initial requirements for the support portal including roles, workflows, and MVP backlog.",
"visibility": "public",
"published_at": new Date('2026-04-03T16:00:00Z'),
"last_reviewed_at": new Date('2026-04-07T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
},
];
const DocumentFilesData = [
{
"name": "atlas-mvp-scope.pdf",
// type code here for "files" field
"content_type": "application/pdf",
"size_bytes": 734003,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "nova-content-inventory.xlsx",
// type code here for "files" field
"content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"size_bytes": 120832,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "orion-observability-plan.pdf",
// type code here for "files" field
"content_type": "application/pdf",
"size_bytes": 654321,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
"name": "helios-requirements-draft.docx",
// type code here for "files" field
"content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"size_bytes": 245120,
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
// 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);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project3 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Project3?.setOwner)
{
await
Project3.
setOwner(relatedOwner3);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
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);
}
const relatedProject3 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Task3?.setProject)
{
await
Task3.
setProject(relatedProject3);
}
}
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);
}
const relatedAssignee3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Task3?.setAssignee)
{
await
Task3.
setAssignee(relatedAssignee3);
}
}
async function associateTaskWithReporter() {
const relatedReporter0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Task0?.setReporter)
{
await
Task0.
setReporter(relatedReporter0);
}
const relatedReporter1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Task1?.setReporter)
{
await
Task1.
setReporter(relatedReporter1);
}
const relatedReporter2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Task2?.setReporter)
{
await
Task2.
setReporter(relatedReporter2);
}
const relatedReporter3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Task3?.setReporter)
{
await
Task3.
setReporter(relatedReporter3);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateCommentWithTask() {
const relatedTask0 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Comment0 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Comment0?.setTask)
{
await
Comment0.
setTask(relatedTask0);
}
const relatedTask1 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Comment1 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Comment1?.setTask)
{
await
Comment1.
setTask(relatedTask1);
}
const relatedTask2 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Comment2 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Comment2?.setTask)
{
await
Comment2.
setTask(relatedTask2);
}
const relatedTask3 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Comment3 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Comment3?.setTask)
{
await
Comment3.
setTask(relatedTask3);
}
}
async function associateCommentWithAuthor() {
const relatedAuthor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Comment0 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Comment0?.setAuthor)
{
await
Comment0.
setAuthor(relatedAuthor0);
}
const relatedAuthor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Comment1 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Comment1?.setAuthor)
{
await
Comment1.
setAuthor(relatedAuthor1);
}
const relatedAuthor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Comment2 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Comment2?.setAuthor)
{
await
Comment2.
setAuthor(relatedAuthor2);
}
const relatedAuthor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Comment3 = await Comments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Comment3?.setAuthor)
{
await
Comment3.
setAuthor(relatedAuthor3);
}
}
async function associateAttachmentWithTask() {
const relatedTask0 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Attachment0 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Attachment0?.setTask)
{
await
Attachment0.
setTask(relatedTask0);
}
const relatedTask1 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Attachment1 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Attachment1?.setTask)
{
await
Attachment1.
setTask(relatedTask1);
}
const relatedTask2 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Attachment2 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Attachment2?.setTask)
{
await
Attachment2.
setTask(relatedTask2);
}
const relatedTask3 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const Attachment3 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Attachment3?.setTask)
{
await
Attachment3.
setTask(relatedTask3);
}
}
async function associateAttachmentWithUploaded_by() {
const relatedUploaded_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attachment0 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Attachment0?.setUploaded_by)
{
await
Attachment0.
setUploaded_by(relatedUploaded_by0);
}
const relatedUploaded_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attachment1 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Attachment1?.setUploaded_by)
{
await
Attachment1.
setUploaded_by(relatedUploaded_by1);
}
const relatedUploaded_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attachment2 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Attachment2?.setUploaded_by)
{
await
Attachment2.
setUploaded_by(relatedUploaded_by2);
}
const relatedUploaded_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Attachment3 = await Attachments.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Attachment3?.setUploaded_by)
{
await
Attachment3.
setUploaded_by(relatedUploaded_by3);
}
}
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);
}
const relatedProject3 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Conversation3 = await Conversations.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Conversation3?.setProject)
{
await
Conversation3.
setProject(relatedProject3);
}
}
// Similar logic for "relation_many"
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);
}
const relatedConversation3 = await Conversations.findOne({
offset: Math.floor(Math.random() * (await Conversations.count())),
});
const Message3 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Message3?.setConversation)
{
await
Message3.
setConversation(relatedConversation3);
}
}
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);
}
}
async function associateDocumentWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Document0 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Document0?.setProject)
{
await
Document0.
setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Document1 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Document1?.setProject)
{
await
Document1.
setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Document2 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Document2?.setProject)
{
await
Document2.
setProject(relatedProject2);
}
const relatedProject3 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Document3 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Document3?.setProject)
{
await
Document3.
setProject(relatedProject3);
}
}
async function associateDocumentWithAuthor() {
const relatedAuthor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Document0 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Document0?.setAuthor)
{
await
Document0.
setAuthor(relatedAuthor0);
}
const relatedAuthor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Document1 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Document1?.setAuthor)
{
await
Document1.
setAuthor(relatedAuthor1);
}
const relatedAuthor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Document2 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Document2?.setAuthor)
{
await
Document2.
setAuthor(relatedAuthor2);
}
const relatedAuthor3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Document3 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Document3?.setAuthor)
{
await
Document3.
setAuthor(relatedAuthor3);
}
}
// Similar logic for "relation_many"
async function associateDocumentFileWithDocument() {
const relatedDocument0 = await Documents.findOne({
offset: Math.floor(Math.random() * (await Documents.count())),
});
const DocumentFile0 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (DocumentFile0?.setDocument)
{
await
DocumentFile0.
setDocument(relatedDocument0);
}
const relatedDocument1 = await Documents.findOne({
offset: Math.floor(Math.random() * (await Documents.count())),
});
const DocumentFile1 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (DocumentFile1?.setDocument)
{
await
DocumentFile1.
setDocument(relatedDocument1);
}
const relatedDocument2 = await Documents.findOne({
offset: Math.floor(Math.random() * (await Documents.count())),
});
const DocumentFile2 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (DocumentFile2?.setDocument)
{
await
DocumentFile2.
setDocument(relatedDocument2);
}
const relatedDocument3 = await Documents.findOne({
offset: Math.floor(Math.random() * (await Documents.count())),
});
const DocumentFile3 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (DocumentFile3?.setDocument)
{
await
DocumentFile3.
setDocument(relatedDocument3);
}
}
async function associateDocumentFileWithUploaded_by() {
const relatedUploaded_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DocumentFile0 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (DocumentFile0?.setUploaded_by)
{
await
DocumentFile0.
setUploaded_by(relatedUploaded_by0);
}
const relatedUploaded_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DocumentFile1 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (DocumentFile1?.setUploaded_by)
{
await
DocumentFile1.
setUploaded_by(relatedUploaded_by1);
}
const relatedUploaded_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DocumentFile2 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (DocumentFile2?.setUploaded_by)
{
await
DocumentFile2.
setUploaded_by(relatedUploaded_by2);
}
const relatedUploaded_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const DocumentFile3 = await DocumentFiles.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (DocumentFile3?.setUploaded_by)
{
await
DocumentFile3.
setUploaded_by(relatedUploaded_by3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Projects.bulkCreate(ProjectsData);
await Tasks.bulkCreate(TasksData);
await Comments.bulkCreate(CommentsData);
await Attachments.bulkCreate(AttachmentsData);
await Conversations.bulkCreate(ConversationsData);
await Messages.bulkCreate(MessagesData);
await Documents.bulkCreate(DocumentsData);
await DocumentFiles.bulkCreate(DocumentFilesData);
await Promise.all([
// Similar logic for "relation_many"
await associateProjectWithOwner(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateTaskWithProject(),
await associateTaskWithAssignee(),
await associateTaskWithReporter(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateCommentWithTask(),
await associateCommentWithAuthor(),
await associateAttachmentWithTask(),
await associateAttachmentWithUploaded_by(),
await associateConversationWithProject(),
// Similar logic for "relation_many"
await associateMessageWithConversation(),
await associateMessageWithSender(),
await associateDocumentWithProject(),
await associateDocumentWithAuthor(),
// Similar logic for "relation_many"
await associateDocumentFileWithDocument(),
await associateDocumentFileWithUploaded_by(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('tasks', null, {});
await queryInterface.bulkDelete('comments', null, {});
await queryInterface.bulkDelete('attachments', null, {});
await queryInterface.bulkDelete('conversations', null, {});
await queryInterface.bulkDelete('messages', null, {});
await queryInterface.bulkDelete('documents', null, {});
await queryInterface.bulkDelete('document_files', null, {});
},
};