const db = require('../models'); const Users = db.users; const Organizations = db.organizations; const Projects = db.projects; const ProjectMemberships = db.project_memberships; const AppTemplates = db.app_templates; const VmPlans = db.vm_plans; const VmSandboxes = db.vm_sandboxes; const ProjectEnvironments = db.project_environments; const AppSpecs = db.app_specs; const GenerationRuns = db.generation_runs; const RunLogs = db.run_logs; const Deployments = db.deployments; const Integrations = db.integrations; const ApiTokens = db.api_tokens; const AuditEvents = db.audit_events; const OrganizationsData = [ { "name": "Alan Turing", }, { "name": "Marie Curie", }, { "name": "Grace Hopper", }, { "name": "Alan Turing", }, { "name": "Alan Turing", }, ]; const ProjectsData = [ { "name": "SaaS Engine Demo Generator", "slug": "saas-engine-demo-generator", "description": "Demo workspace for generating a production-ready SaaS scaffold with RBAC and CRUD.", "visibility": "team", "status": "archived", // type code here for "relation_one" field "archived_at": new Date('2026-02-01T00:00:00Z'), // type code here for "relation_one" field }, { "name": "Customer Support Portal Builder", "slug": "customer-support-portal-builder", "description": "Generate a ticketing portal with roles, workflows, and deployment to a dedicated VM sandbox.", "visibility": "private", "status": "archived", // type code here for "relation_one" field "archived_at": new Date('2026-02-10T00:00:00Z'), // type code here for "relation_one" field }, { "name": "Inventory MicroSaaS Generator", "slug": "inventory-microsaas-generator", "description": "Scaffold an inventory tracking app with API tokens, integrations, and environments.", "visibility": "private", "status": "archived", // type code here for "relation_one" field "archived_at": new Date('2026-02-15T00:00:00Z'), // type code here for "relation_one" field }, { "name": "HR Onboarding Toolkit", "slug": "hr-onboarding-toolkit", "description": "Generate an onboarding app with checklists, files, and audit trails for compliance.", "visibility": "private", "status": "active", // type code here for "relation_one" field "archived_at": new Date('2026-03-01T00:00:00Z'), // type code here for "relation_one" field }, { "name": "Marketing Ops Dashboard", "slug": "marketing-ops-dashboard", "description": "Create a metrics dashboard with scheduled deployments and environment management.", "visibility": "team", "status": "archived", // type code here for "relation_one" field "archived_at": new Date('2026-02-20T00:00:00Z'), // type code here for "relation_one" field }, ]; const ProjectMembershipsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field "membership_role": "owner", "is_invited": false, "joined_at": new Date('2026-03-01T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "membership_role": "viewer", "is_invited": true, "joined_at": new Date('2026-03-02T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "membership_role": "owner", "is_invited": true, "joined_at": new Date('2026-03-03T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "membership_role": "member", "is_invited": true, "joined_at": new Date('2026-03-04T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "membership_role": "admin", "is_invited": false, "joined_at": new Date('2026-03-05T10:00:00Z'), // type code here for "relation_one" field }, ]; const AppTemplatesData = [ { "name": "SAAS Engine", "vendor": "SaaS Engine", "description": "Next.js full-stack template with auth, RBAC, CRUD, and production-ready patterns.", "category": "frontend_only", "license_type": "paid", "price_usd": 399, "repo_url": "https://example.com/saas-engine/repo", "docs_url": "https://example.com/saas-engine/docs", "is_recommended": true, // type code here for "relation_one" field }, { "name": "Django Instant Runtime", "vendor": "Instant Runtime", "description": "Django-based backend with strong admin and rapid modeling for admin-first apps.", "category": "full_stack", "license_type": "free", "price_usd": 0, "repo_url": "https://example.com/django-instant/repo", "docs_url": "https://example.com/django-instant/docs", "is_recommended": true, // type code here for "relation_one" field }, { "name": "Node API Starter", "vendor": "Internal", "description": "Node.js API starter with Postgres, migrations, auth hooks, and background jobs.", "category": "backend_only", "license_type": "paid", "price_usd": 0, "repo_url": "https://example.com/node-api-starter/repo", "docs_url": "https://example.com/node-api-starter/docs", "is_recommended": true, // type code here for "relation_one" field }, { "name": "React Admin Console", "vendor": "Internal", "description": "React dashboard UI with tables, forms, and role-aware navigation components.", "category": "backend_only", "license_type": "paid", "price_usd": 0, "repo_url": "https://example.com/react-admin-console/repo", "docs_url": "https://example.com/react-admin-console/docs", "is_recommended": false, // type code here for "relation_one" field }, { "name": "SaaS Ops Toolkit", "vendor": "OpsWorks", "description": "Opinionated full-stack template focused on deployments, audit logs, and integrations.", "category": "full_stack", "license_type": "paid", "price_usd": 299, "repo_url": "https://example.com/saas-ops-toolkit/repo", "docs_url": "https://example.com/saas-ops-toolkit/docs", "is_recommended": true, // type code here for "relation_one" field }, ]; const VmPlansData = [ { "name": "e2-micro Sandbox", "machine_type": "e2-micro", "vcpu": 2, "memory_gb": 1, "credits_per_day": 0.25, "notes": "Low-cost sandbox plan for quick prototypes and demos.", "is_active": true, // type code here for "relation_one" field }, { "name": "e2-small Sandbox", "machine_type": "e2-small", "vcpu": 2, "memory_gb": 2, "credits_per_day": 0.5, "notes": "Balanced sandbox plan suitable for most generated apps.", "is_active": true, // type code here for "relation_one" field }, { "name": "e2-medium Sandbox", "machine_type": "e2-medium", "vcpu": 2, "memory_gb": 4, "credits_per_day": 0.9, "notes": "More memory for data-heavy apps and larger builds.", "is_active": true, // type code here for "relation_one" field }, { "name": "c3-standard Build", "machine_type": "c3-standard-4", "vcpu": 4, "memory_gb": 8, "credits_per_day": 1.8, "notes": "Faster build and deployment steps for complex apps.", "is_active": true, // type code here for "relation_one" field }, { "name": "Legacy Trial Plan", "machine_type": "n1-standard-1", "vcpu": 1, "memory_gb": 3, "credits_per_day": 0.4, "notes": "Kept for backward compatibility with older sandboxes.", "is_active": true, // type code here for "relation_one" field }, ]; const VmSandboxesData = [ { "name": "sandbox-aigen-001", "provider": "local", "region": "us-central1", "status": "provisioning", "public_url": "https://sbx-001.aigen.dev", "ssh_host": "34.68.120.10", "ssh_port": 22, "ssh_username": "runner", // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { "name": "sandbox-aigen-002", "provider": "gcp", "region": "europe-west1", "status": "error", "public_url": "https://sbx-002.aigen.dev", "ssh_host": "35.195.84.21", "ssh_port": 22, "ssh_username": "runner", // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { "name": "sandbox-aigen-003", "provider": "azure", "region": "us-east-1", "status": "ready", "public_url": "https://sbx-003.aigen.dev", "ssh_host": "3.92.18.44", "ssh_port": 22, "ssh_username": "ec2-user", // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { "name": "sandbox-aigen-004", "provider": "local", "region": "westeurope", "status": "ready", "public_url": "https://sbx-004.aigen.dev", "ssh_host": "20.61.77.19", "ssh_port": 22, "ssh_username": "azureuser", // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, { "name": "sandbox-aigen-005", "provider": "gcp", "region": "asia-southeast1", "status": "ready", "public_url": "https://sbx-005.aigen.dev", "ssh_host": "34.101.110.7", "ssh_port": 22, "ssh_username": "runner", // type code here for "files" field // type code here for "relation_one" field // type code here for "relation_one" field }, ]; const ProjectEnvironmentsData = [ { // type code here for "relation_one" field "name": "Demo Sandbox", "environment_type": "production", "status": "paused", // type code here for "relation_one" field "base_url": "https://demo-saas-engine.sbx-001.aigen.dev", "last_deployed_at": new Date('2026-03-24T14:15:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "Support Sandbox", "environment_type": "production", "status": "deleted", // type code here for "relation_one" field "base_url": "https://support-portal.sbx-002.aigen.dev", "last_deployed_at": new Date('2026-03-23T11:05:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "Inventory Staging", "environment_type": "production", "status": "deleted", // type code here for "relation_one" field "base_url": "https://inventory-stg.sbx-003.aigen.dev", "last_deployed_at": new Date('2026-03-18T09:45:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "HR Production", "environment_type": "sandbox", "status": "creating", // type code here for "relation_one" field "base_url": "https://hr-onboarding.sbx-004.aigen.dev", "last_deployed_at": new Date('2026-03-10T08:20:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "Marketing Sandbox", "environment_type": "sandbox", "status": "deleted", // type code here for "relation_one" field "base_url": "https://marketing-ops.sbx-005.aigen.dev", "last_deployed_at": new Date('2026-03-25T07:30:00Z'), // type code here for "relation_one" field }, ]; const AppSpecsData = [ { // type code here for "relation_one" field "title": "SaaS Engine Baseline Spec", "prompt": "Generate a multi-tenant SaaS dashboard with auth, RBAC, CRUD for projects, and deployment workflows.", "requirements": "Must include user roles, audit events, API tokens, and a deployments page with run logs.", "generated_schema_json": "{entities:[projects,generation_runs,deployments]}", // type code here for "relation_one" field "status": "ready_for_generation", // type code here for "relation_one" field }, { // type code here for "relation_one" field "title": "Support Portal Spec", "prompt": "Build a customer support portal with tickets, internal notes, and deployment to a VM sandbox.", "requirements": "Include roles, audit events, and optional Slack integration for notifications.", "generated_schema_json": "{entities:[tickets,comments,deployments]}", // type code here for "relation_one" field "status": "draft", // type code here for "relation_one" field }, { // type code here for "relation_one" field "title": "Inventory Spec", "prompt": "Create an inventory app with items, locations, adjustments, and an admin console.", "requirements": "Use Postgres, add API tokens for integrations, and provide staging environment deployments.", "generated_schema_json": "{entities:[items,locations,adjustments]}", // type code here for "relation_one" field "status": "locked", // type code here for "relation_one" field }, { // type code here for "relation_one" field "title": "HR Onboarding Spec", "prompt": "Generate an HR onboarding workflow tool with checklists, file uploads, and audit trail.", "requirements": "Emphasize permissions, logs, and production deployment safeguards.", "generated_schema_json": "{entities:[employees,checklists,files]}", // type code here for "relation_one" field "status": "archived", // type code here for "relation_one" field }, { // type code here for "relation_one" field "title": "Marketing Ops Spec", "prompt": "Build a marketing operations dashboard with metrics, reports, and scheduled deployments.", "requirements": "Include audit events, run logs, and GitHub integration for source sync.", "generated_schema_json": "{entities:[metrics,reports,deployments]}", // type code here for "relation_one" field "status": "draft", // type code here for "relation_one" field }, ]; const GenerationRunsData = [ { // type code here for "relation_one" field "status": "running", "trigger": "manual", "started_at": new Date('2026-03-24T13:40:00Z'), "finished_at": new Date('2026-03-24T14:05:00Z'), "duration_seconds": 1500, "branch_name": "gen/saas-engine-baseline", "commit_hash": "a1b2c3d4e5f6", "error_message": "None", // type code here for "files" field // type code here for "relation_one" field }, { // type code here for "relation_one" field "status": "failed", "trigger": "manual", "started_at": new Date('2026-03-19T09:10:00Z'), "finished_at": new Date('2026-03-19T09:18:30Z'), "duration_seconds": 510, "branch_name": "gen/inventory-v1", "commit_hash": "b7c8d9e0f1a2", "error_message": "Build step failed during dependency install", // type code here for "files" field // type code here for "relation_one" field }, { // type code here for "relation_one" field "status": "succeeded", "trigger": "auto", "started_at": new Date('2026-03-25T07:05:00Z'), "finished_at": new Date('2026-03-25T07:10:00Z'), "duration_seconds": 300, "branch_name": "gen/marketing-ops-v1", "commit_hash": "c3d4e5f6a7b8", "error_message": "None", // type code here for "files" field // type code here for "relation_one" field }, { // type code here for "relation_one" field "status": "canceled", "trigger": "auto", "started_at": new Date('2026-03-26T08:00:00Z'), "finished_at": new Date('2026-03-26T08:05:00Z'), "duration_seconds": 300, "branch_name": "gen/support-portal-v1", "commit_hash": "d4e5f6a7b8c9", "error_message": "None", // type code here for "files" field // type code here for "relation_one" field }, { // type code here for "relation_one" field "status": "running", "trigger": "auto", "started_at": new Date('2026-03-20T15:00:00Z'), "finished_at": new Date('2026-03-20T15:02:00Z'), "duration_seconds": 120, "branch_name": "gen/saas-engine-experiment", "commit_hash": "e5f6a7b8c9d0", "error_message": "Canceled by user request", // type code here for "files" field // type code here for "relation_one" field }, ]; const RunLogsData = [ { // type code here for "relation_one" field "level": "debug", "logged_at": new Date('2026-03-24T13:41:00Z'), "message": "Generation started using SAAS Engine template", "source": "generator", // type code here for "relation_one" field }, { // type code here for "relation_one" field "level": "info", "logged_at": new Date('2026-03-24T13:52:00Z'), "message": "Database migrations created successfully", "source": "backend", // type code here for "relation_one" field }, { // type code here for "relation_one" field "level": "info", "logged_at": new Date('2026-03-19T09:16:00Z'), "message": "npm install failed due to dependency conflict", "source": "build", // type code here for "relation_one" field }, { // type code here for "relation_one" field "level": "info", "logged_at": new Date('2026-03-25T07:06:00Z'), "message": "Scaffolding pages and CRUD endpoints", "source": "generator", // type code here for "relation_one" field }, { // type code here for "relation_one" field "level": "warn", "logged_at": new Date('2026-03-20T15:01:00Z'), "message": "Run canceled before deployment step", "source": "orchestrator", // type code here for "relation_one" field }, ]; const DeploymentsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field "action": "rollback", "status": "failed", "requested_at": new Date('2026-03-24T14:06:00Z'), "completed_at": new Date('2026-03-24T14:15:00Z'), "release_tag": "v0.1.0-demo", "deployed_url": "https://demo-saas-engine.sbx-001.aigen.dev", "notes": "Initial demo deployment completed successfully", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "action": "rollback", "status": "canceled", "requested_at": new Date('2026-03-26T08:10:00Z'), "completed_at": new Date('2026-03-26T08:20:00Z'), "release_tag": "v0.1.0-support", "deployed_url": "https://support-portal.sbx-002.aigen.dev", "notes": "Deploy requested after spec draft review", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "action": "deploy", "status": "failed", "requested_at": new Date('2026-03-19T09:20:00Z'), "completed_at": new Date('2026-03-19T09:28:00Z'), "release_tag": "v0.1.0-inventory", "deployed_url": "https://inventory-stg.sbx-003.aigen.dev", "notes": "Deployment failed due to build error in run", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "action": "redeploy", "status": "canceled", "requested_at": new Date('2026-03-10T08:30:00Z'), "completed_at": new Date('2026-03-10T08:40:00Z'), "release_tag": "v0.0.9-hr", "deployed_url": "https://hr-onboarding.sbx-004.aigen.dev", "notes": "Rollback to last known good release", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "action": "redeploy", "status": "queued", "requested_at": new Date('2026-03-20T15:03:00Z'), "completed_at": new Date('2026-03-20T15:05:00Z'), "release_tag": "v0.1.1-demo", "deployed_url": "https://demo-saas-engine.sbx-001.aigen.dev", "notes": "Redeploy canceled while waiting for sandbox capacity", // type code here for "relation_one" field }, ]; const IntegrationsData = [ { // type code here for "relation_one" field "integration_type": "webhook", "name": "GitHub Repo Sync", "external_identifier": "aigen-demo/saas-engine-demo", // type code here for "files" field "webhook_url": "https://api.aigen.dev/webhooks/github/demo", "is_enabled": true, "last_sync_at": new Date('2026-03-24T12:55:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "integration_type": "slack", "name": "Slack Alerts", "external_identifier": "T0123-C0456", // type code here for "files" field "webhook_url": "https://hooks.slack.com/services/T0123/B0456/XYZ123", "is_enabled": true, "last_sync_at": new Date('2026-03-23T10:20:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "integration_type": "slack", "name": "CI Webhook", "external_identifier": "inventory-ci-01", // type code here for "files" field "webhook_url": "https://ci.example.com/hooks/inventory", "is_enabled": false, "last_sync_at": new Date('2026-03-15T09:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "integration_type": "bitbucket", "name": "GitLab Mirror", "external_identifier": "group/marketing-ops", // type code here for "files" field "webhook_url": "https://api.aigen.dev/webhooks/gitlab/marketing", "is_enabled": true, "last_sync_at": new Date('2026-03-25T06:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "integration_type": "bitbucket", "name": "Discord Build Updates", "external_identifier": "channel-981223", // type code here for "files" field "webhook_url": "https://discord.com/api/webhooks/123/abc", "is_enabled": true, "last_sync_at": new Date('2026-03-01T08:00:00Z'), // type code here for "relation_one" field }, ]; const ApiTokensData = [ { // type code here for "relation_one" field "name": "CLI Token", "token_prefix": "aigen_live_7F3K", "scope": "read", "is_revoked": false, "expires_at": new Date('2027-03-01T00:00:00Z'), "last_used_at": new Date('2026-03-25T18:05:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "Automation Token", "token_prefix": "aigen_live_9Q2M", "scope": "write", "is_revoked": true, "expires_at": new Date('2026-12-31T00:00:00Z'), "last_used_at": new Date('2026-03-24T09:15:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "Read Only Token", "token_prefix": "aigen_live_1R8D", "scope": "write", "is_revoked": false, "expires_at": new Date('2026-09-30T00:00:00Z'), "last_used_at": new Date('2026-03-20T11:10:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "Legacy Token", "token_prefix": "aigen_live_6L0P", "scope": "admin", "is_revoked": true, "expires_at": new Date('2026-06-01T00:00:00Z'), "last_used_at": new Date('2026-02-28T10:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "Integration Token", "token_prefix": "aigen_live_3N5X", "scope": "read", "is_revoked": false, "expires_at": new Date('2027-01-15T00:00:00Z'), "last_used_at": new Date('2026-03-23T20:05:00Z'), // type code here for "relation_one" field }, ]; const AuditEventsData = [ { // type code here for "relation_one" field "event_type": "sandbox_provisioned", "entity_name": "projects", "entity_reference": "saas-engine-demo-generator", "metadata_json": "{project:SaaS Engine Demo Generator}", "ip_address": "203.0.113.10", "user_agent": "Mozilla/5.0 Chrome", "occurred_at": new Date('2026-03-01T10:05:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "event_type": "project_created", "entity_name": "app_specs", "entity_reference": "Support Portal Spec", "metadata_json": "{template:SAAS Engine}", "ip_address": "203.0.113.20", "user_agent": "Mozilla/5.0 Chrome", "occurred_at": new Date('2026-03-03T10:30:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "event_type": "sandbox_deleted", "entity_name": "generation_runs", "entity_reference": "gen/inventory-v1", "metadata_json": "{trigger:manual}", "ip_address": "203.0.113.30", "user_agent": "Mozilla/5.0 Firefox", "occurred_at": new Date('2026-03-19T09:10:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "event_type": "project_created", "entity_name": "deployments", "entity_reference": "v0.1.0-demo", "metadata_json": "{status:succeeded}", "ip_address": "203.0.113.10", "user_agent": "Mozilla/5.0 Chrome", "occurred_at": new Date('2026-03-24T14:15:30Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "event_type": "token_revoked", "entity_name": "api_tokens", "entity_reference": "Integration Token", "metadata_json": "{scope:write}", "ip_address": "203.0.113.50", "user_agent": "Mozilla/5.0 Safari", "occurred_at": new Date('2026-03-22T20:00:00Z'), // type code here for "relation_one" field }, ]; // Similar logic for "relation_many" async function associateUserWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0 }); if (User0?.setOrganization) { await User0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1 }); if (User1?.setOrganization) { await User1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2 }); if (User2?.setOrganization) { await User2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User3 = await Users.findOne({ order: [['id', 'ASC']], offset: 3 }); if (User3?.setOrganization) { await User3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const User4 = await Users.findOne({ order: [['id', 'ASC']], offset: 4 }); if (User4?.setOrganization) { await User4. setOrganization(relatedOrganization4); } } 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); } const relatedOwner4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const Project4 = await Projects.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Project4?.setOwner) { await Project4. setOwner(relatedOwner4); } } async function associateProjectWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Project0?.setOrganization) { await Project0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Project1?.setOrganization) { await Project1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Project2?.setOrganization) { await Project2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project3 = await Projects.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Project3?.setOrganization) { await Project3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Project4 = await Projects.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Project4?.setOrganization) { await Project4. setOrganization(relatedOrganization4); } } async function associateProjectMembershipWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectMembership0 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ProjectMembership0?.setProject) { await ProjectMembership0. setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectMembership1 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ProjectMembership1?.setProject) { await ProjectMembership1. setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectMembership2 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ProjectMembership2?.setProject) { await ProjectMembership2. setProject(relatedProject2); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectMembership3 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ProjectMembership3?.setProject) { await ProjectMembership3. setProject(relatedProject3); } const relatedProject4 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectMembership4 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ProjectMembership4?.setProject) { await ProjectMembership4. setProject(relatedProject4); } } async function associateProjectMembershipWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ProjectMembership0 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ProjectMembership0?.setUser) { await ProjectMembership0. setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ProjectMembership1 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ProjectMembership1?.setUser) { await ProjectMembership1. setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ProjectMembership2 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ProjectMembership2?.setUser) { await ProjectMembership2. setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ProjectMembership3 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ProjectMembership3?.setUser) { await ProjectMembership3. setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ProjectMembership4 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ProjectMembership4?.setUser) { await ProjectMembership4. setUser(relatedUser4); } } async function associateProjectMembershipWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectMembership0 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ProjectMembership0?.setOrganization) { await ProjectMembership0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectMembership1 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ProjectMembership1?.setOrganization) { await ProjectMembership1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectMembership2 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ProjectMembership2?.setOrganization) { await ProjectMembership2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectMembership3 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ProjectMembership3?.setOrganization) { await ProjectMembership3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectMembership4 = await ProjectMemberships.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ProjectMembership4?.setOrganization) { await ProjectMembership4. setOrganization(relatedOrganization4); } } async function associateAppTemplateWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppTemplate0 = await AppTemplates.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AppTemplate0?.setOrganization) { await AppTemplate0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppTemplate1 = await AppTemplates.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AppTemplate1?.setOrganization) { await AppTemplate1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppTemplate2 = await AppTemplates.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AppTemplate2?.setOrganization) { await AppTemplate2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppTemplate3 = await AppTemplates.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AppTemplate3?.setOrganization) { await AppTemplate3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppTemplate4 = await AppTemplates.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AppTemplate4?.setOrganization) { await AppTemplate4. setOrganization(relatedOrganization4); } } async function associateVmPlanWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmPlan0 = await VmPlans.findOne({ order: [['id', 'ASC']], offset: 0 }); if (VmPlan0?.setOrganization) { await VmPlan0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmPlan1 = await VmPlans.findOne({ order: [['id', 'ASC']], offset: 1 }); if (VmPlan1?.setOrganization) { await VmPlan1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmPlan2 = await VmPlans.findOne({ order: [['id', 'ASC']], offset: 2 }); if (VmPlan2?.setOrganization) { await VmPlan2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmPlan3 = await VmPlans.findOne({ order: [['id', 'ASC']], offset: 3 }); if (VmPlan3?.setOrganization) { await VmPlan3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmPlan4 = await VmPlans.findOne({ order: [['id', 'ASC']], offset: 4 }); if (VmPlan4?.setOrganization) { await VmPlan4. setOrganization(relatedOrganization4); } } async function associateVmSandboxeWithPlan() { const relatedPlan0 = await VmPlans.findOne({ offset: Math.floor(Math.random() * (await VmPlans.count())), }); const VmSandboxe0 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 0 }); if (VmSandboxe0?.setPlan) { await VmSandboxe0. setPlan(relatedPlan0); } const relatedPlan1 = await VmPlans.findOne({ offset: Math.floor(Math.random() * (await VmPlans.count())), }); const VmSandboxe1 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 1 }); if (VmSandboxe1?.setPlan) { await VmSandboxe1. setPlan(relatedPlan1); } const relatedPlan2 = await VmPlans.findOne({ offset: Math.floor(Math.random() * (await VmPlans.count())), }); const VmSandboxe2 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 2 }); if (VmSandboxe2?.setPlan) { await VmSandboxe2. setPlan(relatedPlan2); } const relatedPlan3 = await VmPlans.findOne({ offset: Math.floor(Math.random() * (await VmPlans.count())), }); const VmSandboxe3 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 3 }); if (VmSandboxe3?.setPlan) { await VmSandboxe3. setPlan(relatedPlan3); } const relatedPlan4 = await VmPlans.findOne({ offset: Math.floor(Math.random() * (await VmPlans.count())), }); const VmSandboxe4 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 4 }); if (VmSandboxe4?.setPlan) { await VmSandboxe4. setPlan(relatedPlan4); } } async function associateVmSandboxeWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmSandboxe0 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 0 }); if (VmSandboxe0?.setOrganization) { await VmSandboxe0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmSandboxe1 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 1 }); if (VmSandboxe1?.setOrganization) { await VmSandboxe1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmSandboxe2 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 2 }); if (VmSandboxe2?.setOrganization) { await VmSandboxe2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmSandboxe3 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 3 }); if (VmSandboxe3?.setOrganization) { await VmSandboxe3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const VmSandboxe4 = await VmSandboxes.findOne({ order: [['id', 'ASC']], offset: 4 }); if (VmSandboxe4?.setOrganization) { await VmSandboxe4. setOrganization(relatedOrganization4); } } async function associateProjectEnvironmentWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectEnvironment0 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ProjectEnvironment0?.setProject) { await ProjectEnvironment0. setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectEnvironment1 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ProjectEnvironment1?.setProject) { await ProjectEnvironment1. setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectEnvironment2 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ProjectEnvironment2?.setProject) { await ProjectEnvironment2. setProject(relatedProject2); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectEnvironment3 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ProjectEnvironment3?.setProject) { await ProjectEnvironment3. setProject(relatedProject3); } const relatedProject4 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const ProjectEnvironment4 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ProjectEnvironment4?.setProject) { await ProjectEnvironment4. setProject(relatedProject4); } } async function associateProjectEnvironmentWithSandbox() { const relatedSandbox0 = await VmSandboxes.findOne({ offset: Math.floor(Math.random() * (await VmSandboxes.count())), }); const ProjectEnvironment0 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ProjectEnvironment0?.setSandbox) { await ProjectEnvironment0. setSandbox(relatedSandbox0); } const relatedSandbox1 = await VmSandboxes.findOne({ offset: Math.floor(Math.random() * (await VmSandboxes.count())), }); const ProjectEnvironment1 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ProjectEnvironment1?.setSandbox) { await ProjectEnvironment1. setSandbox(relatedSandbox1); } const relatedSandbox2 = await VmSandboxes.findOne({ offset: Math.floor(Math.random() * (await VmSandboxes.count())), }); const ProjectEnvironment2 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ProjectEnvironment2?.setSandbox) { await ProjectEnvironment2. setSandbox(relatedSandbox2); } const relatedSandbox3 = await VmSandboxes.findOne({ offset: Math.floor(Math.random() * (await VmSandboxes.count())), }); const ProjectEnvironment3 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ProjectEnvironment3?.setSandbox) { await ProjectEnvironment3. setSandbox(relatedSandbox3); } const relatedSandbox4 = await VmSandboxes.findOne({ offset: Math.floor(Math.random() * (await VmSandboxes.count())), }); const ProjectEnvironment4 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ProjectEnvironment4?.setSandbox) { await ProjectEnvironment4. setSandbox(relatedSandbox4); } } async function associateProjectEnvironmentWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectEnvironment0 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ProjectEnvironment0?.setOrganization) { await ProjectEnvironment0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectEnvironment1 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ProjectEnvironment1?.setOrganization) { await ProjectEnvironment1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectEnvironment2 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ProjectEnvironment2?.setOrganization) { await ProjectEnvironment2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectEnvironment3 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ProjectEnvironment3?.setOrganization) { await ProjectEnvironment3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ProjectEnvironment4 = await ProjectEnvironments.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ProjectEnvironment4?.setOrganization) { await ProjectEnvironment4. setOrganization(relatedOrganization4); } } async function associateAppSpecWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const AppSpec0 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AppSpec0?.setProject) { await AppSpec0. setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const AppSpec1 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AppSpec1?.setProject) { await AppSpec1. setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const AppSpec2 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AppSpec2?.setProject) { await AppSpec2. setProject(relatedProject2); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const AppSpec3 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AppSpec3?.setProject) { await AppSpec3. setProject(relatedProject3); } const relatedProject4 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const AppSpec4 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AppSpec4?.setProject) { await AppSpec4. setProject(relatedProject4); } } async function associateAppSpecWithTemplate() { const relatedTemplate0 = await AppTemplates.findOne({ offset: Math.floor(Math.random() * (await AppTemplates.count())), }); const AppSpec0 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AppSpec0?.setTemplate) { await AppSpec0. setTemplate(relatedTemplate0); } const relatedTemplate1 = await AppTemplates.findOne({ offset: Math.floor(Math.random() * (await AppTemplates.count())), }); const AppSpec1 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AppSpec1?.setTemplate) { await AppSpec1. setTemplate(relatedTemplate1); } const relatedTemplate2 = await AppTemplates.findOne({ offset: Math.floor(Math.random() * (await AppTemplates.count())), }); const AppSpec2 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AppSpec2?.setTemplate) { await AppSpec2. setTemplate(relatedTemplate2); } const relatedTemplate3 = await AppTemplates.findOne({ offset: Math.floor(Math.random() * (await AppTemplates.count())), }); const AppSpec3 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AppSpec3?.setTemplate) { await AppSpec3. setTemplate(relatedTemplate3); } const relatedTemplate4 = await AppTemplates.findOne({ offset: Math.floor(Math.random() * (await AppTemplates.count())), }); const AppSpec4 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AppSpec4?.setTemplate) { await AppSpec4. setTemplate(relatedTemplate4); } } async function associateAppSpecWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSpec0 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AppSpec0?.setOrganization) { await AppSpec0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSpec1 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AppSpec1?.setOrganization) { await AppSpec1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSpec2 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AppSpec2?.setOrganization) { await AppSpec2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSpec3 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AppSpec3?.setOrganization) { await AppSpec3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSpec4 = await AppSpecs.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AppSpec4?.setOrganization) { await AppSpec4. setOrganization(relatedOrganization4); } } async function associateGenerationRunWithSpec() { const relatedSpec0 = await AppSpecs.findOne({ offset: Math.floor(Math.random() * (await AppSpecs.count())), }); const GenerationRun0 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 0 }); if (GenerationRun0?.setSpec) { await GenerationRun0. setSpec(relatedSpec0); } const relatedSpec1 = await AppSpecs.findOne({ offset: Math.floor(Math.random() * (await AppSpecs.count())), }); const GenerationRun1 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 1 }); if (GenerationRun1?.setSpec) { await GenerationRun1. setSpec(relatedSpec1); } const relatedSpec2 = await AppSpecs.findOne({ offset: Math.floor(Math.random() * (await AppSpecs.count())), }); const GenerationRun2 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 2 }); if (GenerationRun2?.setSpec) { await GenerationRun2. setSpec(relatedSpec2); } const relatedSpec3 = await AppSpecs.findOne({ offset: Math.floor(Math.random() * (await AppSpecs.count())), }); const GenerationRun3 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 3 }); if (GenerationRun3?.setSpec) { await GenerationRun3. setSpec(relatedSpec3); } const relatedSpec4 = await AppSpecs.findOne({ offset: Math.floor(Math.random() * (await AppSpecs.count())), }); const GenerationRun4 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 4 }); if (GenerationRun4?.setSpec) { await GenerationRun4. setSpec(relatedSpec4); } } async function associateGenerationRunWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const GenerationRun0 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 0 }); if (GenerationRun0?.setOrganization) { await GenerationRun0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const GenerationRun1 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 1 }); if (GenerationRun1?.setOrganization) { await GenerationRun1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const GenerationRun2 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 2 }); if (GenerationRun2?.setOrganization) { await GenerationRun2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const GenerationRun3 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 3 }); if (GenerationRun3?.setOrganization) { await GenerationRun3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const GenerationRun4 = await GenerationRuns.findOne({ order: [['id', 'ASC']], offset: 4 }); if (GenerationRun4?.setOrganization) { await GenerationRun4. setOrganization(relatedOrganization4); } } async function associateRunLogWithRun() { const relatedRun0 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const RunLog0 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (RunLog0?.setRun) { await RunLog0. setRun(relatedRun0); } const relatedRun1 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const RunLog1 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (RunLog1?.setRun) { await RunLog1. setRun(relatedRun1); } const relatedRun2 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const RunLog2 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (RunLog2?.setRun) { await RunLog2. setRun(relatedRun2); } const relatedRun3 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const RunLog3 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 3 }); if (RunLog3?.setRun) { await RunLog3. setRun(relatedRun3); } const relatedRun4 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const RunLog4 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 4 }); if (RunLog4?.setRun) { await RunLog4. setRun(relatedRun4); } } async function associateRunLogWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const RunLog0 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 0 }); if (RunLog0?.setOrganization) { await RunLog0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const RunLog1 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 1 }); if (RunLog1?.setOrganization) { await RunLog1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const RunLog2 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 2 }); if (RunLog2?.setOrganization) { await RunLog2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const RunLog3 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 3 }); if (RunLog3?.setOrganization) { await RunLog3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const RunLog4 = await RunLogs.findOne({ order: [['id', 'ASC']], offset: 4 }); if (RunLog4?.setOrganization) { await RunLog4. setOrganization(relatedOrganization4); } } async function associateDeploymentWithEnvironment() { const relatedEnvironment0 = await ProjectEnvironments.findOne({ offset: Math.floor(Math.random() * (await ProjectEnvironments.count())), }); const Deployment0 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deployment0?.setEnvironment) { await Deployment0. setEnvironment(relatedEnvironment0); } const relatedEnvironment1 = await ProjectEnvironments.findOne({ offset: Math.floor(Math.random() * (await ProjectEnvironments.count())), }); const Deployment1 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deployment1?.setEnvironment) { await Deployment1. setEnvironment(relatedEnvironment1); } const relatedEnvironment2 = await ProjectEnvironments.findOne({ offset: Math.floor(Math.random() * (await ProjectEnvironments.count())), }); const Deployment2 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deployment2?.setEnvironment) { await Deployment2. setEnvironment(relatedEnvironment2); } const relatedEnvironment3 = await ProjectEnvironments.findOne({ offset: Math.floor(Math.random() * (await ProjectEnvironments.count())), }); const Deployment3 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Deployment3?.setEnvironment) { await Deployment3. setEnvironment(relatedEnvironment3); } const relatedEnvironment4 = await ProjectEnvironments.findOne({ offset: Math.floor(Math.random() * (await ProjectEnvironments.count())), }); const Deployment4 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Deployment4?.setEnvironment) { await Deployment4. setEnvironment(relatedEnvironment4); } } async function associateDeploymentWithRun() { const relatedRun0 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const Deployment0 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deployment0?.setRun) { await Deployment0. setRun(relatedRun0); } const relatedRun1 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const Deployment1 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deployment1?.setRun) { await Deployment1. setRun(relatedRun1); } const relatedRun2 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const Deployment2 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deployment2?.setRun) { await Deployment2. setRun(relatedRun2); } const relatedRun3 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const Deployment3 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Deployment3?.setRun) { await Deployment3. setRun(relatedRun3); } const relatedRun4 = await GenerationRuns.findOne({ offset: Math.floor(Math.random() * (await GenerationRuns.count())), }); const Deployment4 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Deployment4?.setRun) { await Deployment4. setRun(relatedRun4); } } async function associateDeploymentWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Deployment0 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Deployment0?.setOrganization) { await Deployment0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Deployment1 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Deployment1?.setOrganization) { await Deployment1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Deployment2 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Deployment2?.setOrganization) { await Deployment2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Deployment3 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Deployment3?.setOrganization) { await Deployment3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Deployment4 = await Deployments.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Deployment4?.setOrganization) { await Deployment4. setOrganization(relatedOrganization4); } } async function associateIntegrationWithProject() { const relatedProject0 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Integration0 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Integration0?.setProject) { await Integration0. setProject(relatedProject0); } const relatedProject1 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Integration1 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Integration1?.setProject) { await Integration1. setProject(relatedProject1); } const relatedProject2 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Integration2 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Integration2?.setProject) { await Integration2. setProject(relatedProject2); } const relatedProject3 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Integration3 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Integration3?.setProject) { await Integration3. setProject(relatedProject3); } const relatedProject4 = await Projects.findOne({ offset: Math.floor(Math.random() * (await Projects.count())), }); const Integration4 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Integration4?.setProject) { await Integration4. setProject(relatedProject4); } } async function associateIntegrationWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Integration0 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Integration0?.setOrganization) { await Integration0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Integration1 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Integration1?.setOrganization) { await Integration1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Integration2 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Integration2?.setOrganization) { await Integration2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Integration3 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Integration3?.setOrganization) { await Integration3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Integration4 = await Integrations.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Integration4?.setOrganization) { await Integration4. setOrganization(relatedOrganization4); } } async function associateApiTokenWithUser() { const relatedUser0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ApiToken0 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ApiToken0?.setUser) { await ApiToken0. setUser(relatedUser0); } const relatedUser1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ApiToken1 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ApiToken1?.setUser) { await ApiToken1. setUser(relatedUser1); } const relatedUser2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ApiToken2 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ApiToken2?.setUser) { await ApiToken2. setUser(relatedUser2); } const relatedUser3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ApiToken3 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ApiToken3?.setUser) { await ApiToken3. setUser(relatedUser3); } const relatedUser4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const ApiToken4 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ApiToken4?.setUser) { await ApiToken4. setUser(relatedUser4); } } async function associateApiTokenWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ApiToken0 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 0 }); if (ApiToken0?.setOrganization) { await ApiToken0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ApiToken1 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 1 }); if (ApiToken1?.setOrganization) { await ApiToken1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ApiToken2 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 2 }); if (ApiToken2?.setOrganization) { await ApiToken2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ApiToken3 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 3 }); if (ApiToken3?.setOrganization) { await ApiToken3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const ApiToken4 = await ApiTokens.findOne({ order: [['id', 'ASC']], offset: 4 }); if (ApiToken4?.setOrganization) { await ApiToken4. setOrganization(relatedOrganization4); } } 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); } const relatedActor3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent3 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AuditEvent3?.setActor) { await AuditEvent3. setActor(relatedActor3); } const relatedActor4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent4 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AuditEvent4?.setActor) { await AuditEvent4. setActor(relatedActor4); } } async function associateAuditEventWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AuditEvent0 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AuditEvent0?.setOrganization) { await AuditEvent0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AuditEvent1 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AuditEvent1?.setOrganization) { await AuditEvent1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AuditEvent2 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AuditEvent2?.setOrganization) { await AuditEvent2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AuditEvent3 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AuditEvent3?.setOrganization) { await AuditEvent3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AuditEvent4 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AuditEvent4?.setOrganization) { await AuditEvent4. setOrganization(relatedOrganization4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Organizations.bulkCreate(OrganizationsData); await Projects.bulkCreate(ProjectsData); await ProjectMemberships.bulkCreate(ProjectMembershipsData); await AppTemplates.bulkCreate(AppTemplatesData); await VmPlans.bulkCreate(VmPlansData); await VmSandboxes.bulkCreate(VmSandboxesData); await ProjectEnvironments.bulkCreate(ProjectEnvironmentsData); await AppSpecs.bulkCreate(AppSpecsData); await GenerationRuns.bulkCreate(GenerationRunsData); await RunLogs.bulkCreate(RunLogsData); await Deployments.bulkCreate(DeploymentsData); await Integrations.bulkCreate(IntegrationsData); await ApiTokens.bulkCreate(ApiTokensData); await AuditEvents.bulkCreate(AuditEventsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateProjectWithOwner(), await associateProjectWithOrganization(), await associateProjectMembershipWithProject(), await associateProjectMembershipWithUser(), await associateProjectMembershipWithOrganization(), await associateAppTemplateWithOrganization(), await associateVmPlanWithOrganization(), await associateVmSandboxeWithPlan(), await associateVmSandboxeWithOrganization(), await associateProjectEnvironmentWithProject(), await associateProjectEnvironmentWithSandbox(), await associateProjectEnvironmentWithOrganization(), await associateAppSpecWithProject(), await associateAppSpecWithTemplate(), await associateAppSpecWithOrganization(), await associateGenerationRunWithSpec(), await associateGenerationRunWithOrganization(), await associateRunLogWithRun(), await associateRunLogWithOrganization(), await associateDeploymentWithEnvironment(), await associateDeploymentWithRun(), await associateDeploymentWithOrganization(), await associateIntegrationWithProject(), await associateIntegrationWithOrganization(), await associateApiTokenWithUser(), await associateApiTokenWithOrganization(), await associateAuditEventWithActor(), await associateAuditEventWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('organizations', null, {}); await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('project_memberships', null, {}); await queryInterface.bulkDelete('app_templates', null, {}); await queryInterface.bulkDelete('vm_plans', null, {}); await queryInterface.bulkDelete('vm_sandboxes', null, {}); await queryInterface.bulkDelete('project_environments', null, {}); await queryInterface.bulkDelete('app_specs', null, {}); await queryInterface.bulkDelete('generation_runs', null, {}); await queryInterface.bulkDelete('run_logs', null, {}); await queryInterface.bulkDelete('deployments', null, {}); await queryInterface.bulkDelete('integrations', null, {}); await queryInterface.bulkDelete('api_tokens', null, {}); await queryInterface.bulkDelete('audit_events', null, {}); }, };