const db = require('../models'); const Users = db.users; const Projects = db.projects; const Environments = db.environments; const Features = db.features; const Tasks = db.tasks; const Comments = db.comments; const Assets = db.assets; const Deployments = db.deployments; const DeploymentLogs = db.deployment_logs; const AuditEvents = db.audit_events; const AppSettings = db.app_settings; const ProjectsData = [ { "name": "Template Starter Kit", "summary": "Reference project for the CRUD template and baseline configuration.", "status": "active", "start_at": new Date('2026-04-01T09:00:00Z'), "end_at": new Date('2026-06-30T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field }, { "name": "Onboarding Experience", "summary": "Improve sign-in, invitations, and first-run setup flows.", "status": "archived", "start_at": new Date('2026-05-01T09:00:00Z'), "end_at": new Date('2026-07-15T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field }, { "name": "Access Control Refresh", "summary": "Role and permission model cleanup with better auditability.", "status": "archived", "start_at": new Date('2026-05-05T09:00:00Z'), "end_at": new Date('2026-06-20T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_many" field // type code here for "relation_many" field }, ]; const EnvironmentsData = [ { "name": "Template Dev", "kind": "staging", "base_url": "https://dev.template.apppreview.io", "active": true, // type code here for "relation_one" field // type code here for "relation_many" field }, { "name": "Template Staging", "kind": "development", "base_url": "https://staging.template.apppreview.io", "active": true, // type code here for "relation_one" field // type code here for "relation_many" field }, { "name": "Template Prod", "kind": "staging", "base_url": "https://template.apppreview.io", "active": true, // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const FeaturesData = [ { "name": "Invitation Emails", "details": "Send invitation emails with expiring links and basic rate limiting.", "priority": "low", "state": "in_progress", "target_start_at": new Date('2026-05-02T09:00:00Z'), "target_end_at": new Date('2026-05-28T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, { "name": "Role Assignment UI", "details": "Allow privileged users to assign roles to teammates with clear confirmation.", "priority": "low", "state": "planned", "target_start_at": new Date('2026-05-25T09:00:00Z'), "target_end_at": new Date('2026-06-12T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, { "name": "Audit Trail Filters", "details": "Filter audit events by actor, date range, and entity for investigation.", "priority": "critical", "state": "backlog", "target_start_at": new Date('2026-06-01T09:00:00Z'), "target_end_at": new Date('2026-06-25T17:00:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const TasksData = [ { "title": "Add invite token expiry", "description": "Store invite token creation time and reject tokens after the expiry window.", "status": "blocked", "severity": "critical", "estimate_points": 5, "due_at": new Date('2026-05-27T17:00:00Z'), // 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_one" field // type code here for "relation_many" field // type code here for "relation_many" field }, { "title": "Create roles page table", "description": "Implement roles list with name, description, and linked permissions count.", "status": "blocked", "severity": "critical", "estimate_points": 3, "due_at": new Date('2026-06-03T17:00:00Z'), // 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_one" field // type code here for "relation_many" field // type code here for "relation_many" field }, { "title": "Add audit event search", "description": "Support searching audit events by entity name and key.", "status": "review", "severity": "minor", "estimate_points": 3, "due_at": new Date('2026-06-10T17:00:00Z'), // 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_one" field // type code here for "relation_many" field // type code here for "relation_many" field }, ]; const CommentsData = [ { "body": "I will add a configurable expiry window and document it in settings.", "posted_at": new Date('2026-05-20T11:15:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, { "body": "The roles table should sort by name and support quick search.", "posted_at": new Date('2026-05-20T13:40:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, { "body": "We should index entity_name and entity_key for faster filtering.", "posted_at": new Date('2026-05-21T09:05:00Z'), // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const AssetsData = [ { "name": "Access Policy Draft", "asset_type": "file", // type code here for "images" field // type code here for "files" field "mime_type": "application/pdf", "size_mb": 0.8, // type code here for "relation_one" field }, { "name": "Deployment Checklist", "asset_type": "file", // type code here for "images" field // type code here for "files" field "mime_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "size_mb": 0.4, // type code here for "relation_one" field }, { "name": "UI Screenshot Roles", "asset_type": "image", // type code here for "images" field // type code here for "files" field "mime_type": "image/png", "size_mb": 0.2, // type code here for "relation_one" field }, ]; const DeploymentsData = [ { "version_label": "v0.9.0", "status": "canceled", "started_at": new Date('2026-05-10T10:00:00Z'), "finished_at": new Date('2026-05-10T10:12:00Z'), "notes": "Staging deploy for deployment history view.", // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, { "version_label": "v0.9.1", "status": "queued", "started_at": new Date('2026-05-12T15:30:00Z'), "finished_at": new Date('2026-05-12T15:44:00Z'), "notes": "Failed due to missing environment variable.", // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, { "version_label": "v0.9.2", "status": "succeeded", "started_at": new Date('2026-05-14T09:20:00Z'), "finished_at": new Date('2026-05-14T09:33:00Z'), "notes": "Hotfix for invite link rendering.", // type code here for "relation_one" field // type code here for "relation_one" field // type code here for "relation_many" field }, ]; const DeploymentLogsData = [ { "logged_at": new Date('2026-05-10T10:01:00Z'), "level": "error", "message": "Build started with commit 2f3a1c", // type code here for "relation_one" field }, { "logged_at": new Date('2026-05-10T10:06:00Z'), "level": "info", "message": "Database migrations completed", // type code here for "relation_one" field }, { "logged_at": new Date('2026-05-12T15:41:00Z'), "level": "warn", "message": "Missing ENV DEPLOY_TOKEN in staging", // type code here for "relation_one" field }, ]; const AuditEventsData = [ { "occurred_at": new Date('2026-05-18T09:12:10Z'), "event_type": "delete", "entity_name": "users", "entity_key": "avery.morgan@apppreview.io", "details": "User login successful", "ip_address": "203.0.113.10", // type code here for "relation_one" field }, { "occurred_at": new Date('2026-05-19T14:47:22Z'), "event_type": "login", "entity_name": "projects", "entity_key": "Template Starter Kit", "details": "Updated project summary", "ip_address": "203.0.113.11", // type code here for "relation_one" field }, { "occurred_at": new Date('2026-05-20T08:05:44Z'), "event_type": "delete", "entity_name": "deployments", "entity_key": "v0.9.2", "details": "Deployment created for staging", "ip_address": "203.0.113.12", // type code here for "relation_one" field }, ]; const AppSettingsData = [ { "key": "invite_expiry_hours", "value": "48", "value_type": "decimal", "description": "Invitation link expiry window in hours.", "is_secret": false, }, { "key": "password_min_length", "value": "12", "value_type": "int", "description": "Minimum password length for new users.", "is_secret": false, }, { "key": "session_timeout_minutes", "value": "60", "value_type": "boolean", "description": "Idle session timeout in minutes.", "is_secret": true, }, ]; // 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); } } // Similar logic for "relation_many" // Similar logic for "relation_many" async function associateEnvironmentWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Environment0 = await Environments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Environment0?.setProject) { await Environment0. setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Environment1 = await Environments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Environment1?.setProject) { await Environment1. setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Environment2 = await Environments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Environment2?.setProject) { await Environment2. setProject(relatedProject2); } } // Similar logic for "relation_many" async function associateFeatureWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Feature0 = await Features.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Feature0?.setProject) { await Feature0. setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Feature1 = await Features.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Feature1?.setProject) { await Feature1. setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Feature2 = await Features.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Feature2?.setProject) { await Feature2. setProject(relatedProject2); } } async function associateFeatureWithAssignee() { const relatedAssignee0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feature0 = await Features.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Feature0?.setAssignee) { await Feature0. setAssignee(relatedAssignee0); } const relatedAssignee1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feature1 = await Features.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Feature1?.setAssignee) { await Feature1. setAssignee(relatedAssignee1); } const relatedAssignee2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Feature2 = await Features.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Feature2?.setAssignee) { await Feature2. setAssignee(relatedAssignee2); } } // 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); } } async function associateTaskWithFeature() { const relatedFeature0 = await Features.findOne({ offset: Math.floor(Math.random() * (await Features.count())), }); const Task0 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Task0?.setFeature) { await Task0. setFeature(relatedFeature0); } const relatedFeature1 = await Features.findOne({ offset: Math.floor(Math.random() * (await Features.count())), }); const Task1 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Task1?.setFeature) { await Task1. setFeature(relatedFeature1); } const relatedFeature2 = await Features.findOne({ offset: Math.floor(Math.random() * (await Features.count())), }); const Task2 = await Tasks.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Task2?.setFeature) { await Task2. setFeature(relatedFeature2); } } 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); } } 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); } } // Similar logic for "relation_many" // Similar logic for "relation_many" 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); } } 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); } } // Similar logic for "relation_many" async function associateAssetWithUploaded_by() { const relatedUploaded_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Asset0 = await Assets.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Asset0?.setUploaded_by) { await Asset0. setUploaded_by(relatedUploaded_by0); } const relatedUploaded_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Asset1 = await Assets.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Asset1?.setUploaded_by) { await Asset1. setUploaded_by(relatedUploaded_by1); } const relatedUploaded_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Asset2 = await Assets.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Asset2?.setUploaded_by) { await Asset2. setUploaded_by(relatedUploaded_by2); } } async function associateDeploymentWithEnvironment() { const relatedEnvironment0 = await Environments.findOne({ offset: Math.floor(Math.random() * (await Environments.count())), }); const Deployment0 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deployment0?.setEnvironment) { await Deployment0. setEnvironment(relatedEnvironment0); } const relatedEnvironment1 = await Environments.findOne({ offset: Math.floor(Math.random() * (await Environments.count())), }); const Deployment1 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deployment1?.setEnvironment) { await Deployment1. setEnvironment(relatedEnvironment1); } const relatedEnvironment2 = await Environments.findOne({ offset: Math.floor(Math.random() * (await Environments.count())), }); const Deployment2 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deployment2?.setEnvironment) { await Deployment2. setEnvironment(relatedEnvironment2); } } async function associateDeploymentWithTriggered_by() { const relatedTriggered_by0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deployment0 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deployment0?.setTriggered_by) { await Deployment0. setTriggered_by(relatedTriggered_by0); } const relatedTriggered_by1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deployment1 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deployment1?.setTriggered_by) { await Deployment1. setTriggered_by(relatedTriggered_by1); } const relatedTriggered_by2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Deployment2 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deployment2?.setTriggered_by) { await Deployment2. setTriggered_by(relatedTriggered_by2); } } // Similar logic for "relation_many" async function associateDeploymentLogWithDeployment() { const relatedDeployment0 = await Deployments.findOne({ offset: Math.floor(Math.random() * (await Deployments.count())), }); const DeploymentLog0 = await DeploymentLogs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (DeploymentLog0?.setDeployment) { await DeploymentLog0. setDeployment(relatedDeployment0); } const relatedDeployment1 = await Deployments.findOne({ offset: Math.floor(Math.random() * (await Deployments.count())), }); const DeploymentLog1 = await DeploymentLogs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (DeploymentLog1?.setDeployment) { await DeploymentLog1. setDeployment(relatedDeployment1); } const relatedDeployment2 = await Deployments.findOne({ offset: Math.floor(Math.random() * (await Deployments.count())), }); const DeploymentLog2 = await DeploymentLogs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (DeploymentLog2?.setDeployment) { await DeploymentLog2. setDeployment(relatedDeployment2); } } async function associateAuditEventWithActor() { const relatedActor0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent0 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AuditEvent0?.setActor) { await AuditEvent0. setActor(relatedActor0); } const relatedActor1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent1 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AuditEvent1?.setActor) { await AuditEvent1. setActor(relatedActor1); } const relatedActor2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent2 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AuditEvent2?.setActor) { await AuditEvent2. setActor(relatedActor2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Projects.bulkCreate(ProjectsData); await Environments.bulkCreate(EnvironmentsData); await Features.bulkCreate(FeaturesData); await Tasks.bulkCreate(TasksData); await Comments.bulkCreate(CommentsData); await Assets.bulkCreate(AssetsData); await Deployments.bulkCreate(DeploymentsData); await DeploymentLogs.bulkCreate(DeploymentLogsData); await AuditEvents.bulkCreate(AuditEventsData); await AppSettings.bulkCreate(AppSettingsData); await Promise.all([ // Similar logic for "relation_many" await associateProjectWithOwner(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associateEnvironmentWithProject(), // Similar logic for "relation_many" await associateFeatureWithProject(), await associateFeatureWithAssignee(), // Similar logic for "relation_many" await associateTaskWithProject(), await associateTaskWithFeature(), await associateTaskWithReporter(), await associateTaskWithAssignee(), // Similar logic for "relation_many" // Similar logic for "relation_many" await associateCommentWithAuthor(), await associateCommentWithTask(), // Similar logic for "relation_many" await associateAssetWithUploaded_by(), await associateDeploymentWithEnvironment(), await associateDeploymentWithTriggered_by(), // Similar logic for "relation_many" await associateDeploymentLogWithDeployment(), await associateAuditEventWithActor(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('environments', null, {}); await queryInterface.bulkDelete('features', null, {}); await queryInterface.bulkDelete('tasks', null, {}); await queryInterface.bulkDelete('comments', null, {}); await queryInterface.bulkDelete('assets', null, {}); await queryInterface.bulkDelete('deployments', null, {}); await queryInterface.bulkDelete('deployment_logs', null, {}); await queryInterface.bulkDelete('audit_events', null, {}); await queryInterface.bulkDelete('app_settings', null, {}); }, };