const db = require('../models'); const Users = db.users; const Organizations = db.organizations; const Workspaces = db.workspaces; const SlackChannels = db.slack_channels; const AgentClients = db.agent_clients; const McpToolCalls = db.mcp_tool_calls; const SlackMessages = db.slack_messages; const HumanReplies = db.human_replies; const Uploads = db.uploads; const Webhooks = db.webhooks; const AuditEvents = db.audit_events; const AppSettings = db.app_settings; const OrganizationsData = [ { "name": "Ada Lovelace", }, { "name": "Ada Lovelace", }, { "name": "Alan Turing", }, { "name": "Alan Turing", }, { "name": "Ada Lovelace", }, ]; const WorkspacesData = [ { "name": "Acme Product Studio", "slack_team_id": "T024ACME01", "install_status": "installed", "installed_at": new Date('2026-01-15T13:20:00Z'), "revoked_at": new Date('2026-01-01T00:00:00Z'), "bot_token_hint": "xoxb-...ACME", "is_default": true, // type code here for "relation_one" field }, { "name": "Northwind Research", "slack_team_id": "T024NWIND1", "install_status": "revoked", "installed_at": new Date('2026-02-01T09:00:00Z'), "revoked_at": new Date('2026-01-01T00:00:00Z'), "bot_token_hint": "xoxb-...NWIND", "is_default": false, // type code here for "relation_one" field }, { "name": "Blue Oak Labs", "slack_team_id": "T024BLUE01", "install_status": "not_installed", "installed_at": new Date('2026-01-01T00:00:00Z'), "revoked_at": new Date('2026-01-01T00:00:00Z'), "bot_token_hint": "pending", "is_default": false, // type code here for "relation_one" field }, { "name": "Helios Design Team", "slack_team_id": "T024HELIOS", "install_status": "revoked", "installed_at": new Date('2025-12-05T17:30:00Z'), "revoked_at": new Date('2026-01-20T12:10:00Z'), "bot_token_hint": "xoxb-...HELIOS", "is_default": false, // type code here for "relation_one" field }, { "name": "Contoso Commerce", "slack_team_id": "T024CONT01", "install_status": "not_installed", "installed_at": new Date('2026-02-10T15:45:00Z'), "revoked_at": new Date('2026-01-01T00:00:00Z'), "bot_token_hint": "xoxb-...CONT", "is_default": false, // type code here for "relation_one" field }, ]; const SlackChannelsData = [ { // type code here for "relation_one" field "name": "ai-requests", "slack_channel_id": "C024ACME01", "is_default": true, "is_private": true, "is_archived": false, // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "design-ops", "slack_channel_id": "C024ACME02", "is_default": true, "is_private": true, "is_archived": false, // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "agent-alerts", "slack_channel_id": "C024NWIND1", "is_default": true, "is_private": false, "is_archived": true, // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "content-review", "slack_channel_id": "C024CONT1", "is_default": true, "is_private": false, "is_archived": true, // type code here for "relation_one" field }, { // type code here for "relation_one" field "name": "inbox", "slack_channel_id": "C024HELI1", "is_default": true, "is_private": true, "is_archived": true, // type code here for "relation_one" field }, ]; const AgentClientsData = [ { "name": "UI Agent Prod", "client_type": "mcp_http", "api_key_prefix": "ak_ui_prod", "status": "active", // type code here for "relation_one" field // type code here for "relation_one" field "last_seen_at": new Date('2026-02-22T12:04:55Z'), // type code here for "relation_one" field }, { "name": "Docs Agent Staging", "client_type": "mcp_http", "api_key_prefix": "ak_docs_stg", "status": "active", // type code here for "relation_one" field // type code here for "relation_one" field "last_seen_at": new Date('2026-02-21T18:20:01Z'), // type code here for "relation_one" field }, { "name": "Research Agent", "client_type": "internal_service", "api_key_prefix": "ak_research", "status": "disabled", // type code here for "relation_one" field // type code here for "relation_one" field "last_seen_at": new Date('2026-02-23T07:11:39Z'), // type code here for "relation_one" field }, { "name": "Commerce Ops Bot", "client_type": "mcp_http", "api_key_prefix": "ak_com_ops", "status": "disabled", // type code here for "relation_one" field // type code here for "relation_one" field "last_seen_at": new Date('2026-02-24T09:40:12Z'), // type code here for "relation_one" field }, { "name": "Legacy Agent", "client_type": "internal_service", "api_key_prefix": "ak_legacy", "status": "active", // type code here for "relation_one" field // type code here for "relation_one" field "last_seen_at": new Date('2026-01-12T10:10:10Z'), // type code here for "relation_one" field }, ]; const McpToolCallsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field "tool_name": "send_slack_message", "request_status": "failed", "received_at": new Date('2026-02-22T12:03:10Z'), "processed_at": new Date('2026-02-22T12:03:12Z'), "request_id": "req_7b3c2c0a", "trace_id": "trace_9f11a2", "raw_payload": "{channel:#ai-requests,text:Please create a hero image concept for the pricing page.}", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "tool_name": "send_slack_message", "request_status": "failed", "received_at": new Date('2026-02-21T18:18:40Z'), "processed_at": new Date('2026-02-21T18:18:41Z'), "request_id": "req_1d0c54e9", "trace_id": "trace_2a88d1", "raw_payload": "{channel:#design-ops,text:Need updated diagram for onboarding flow.}", "error_message": "Slack API rate_limited", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "tool_name": "send_slack_message", "request_status": "received", "received_at": new Date('2026-02-23T07:10:01Z'), "processed_at": new Date('2026-02-23T07:10:03Z'), "request_id": "req_5f0d9a12", "trace_id": "trace_7c0b3d", "raw_payload": "{channel:#agent-alerts,text:Please review the summary for accuracy and add citations.}", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "tool_name": "send_slack_message", "request_status": "received", "received_at": new Date('2026-02-24T09:38:20Z'), "processed_at": new Date('2026-02-24T09:38:22Z'), "request_id": "req_c8aa311e", "trace_id": "trace_1b9c02", "raw_payload": "{channel:#content-review,text:Can you approve the new product description draft by EOD?}", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "tool_name": "send_slack_message", "request_status": "failed", "received_at": new Date('2026-02-20T10:22:00Z'), "processed_at": new Date('2026-02-20T10:22:05Z'), "request_id": "req_3e4a9c77", "trace_id": "trace_6d12e0", "raw_payload": "{channel:#ai-requests,text:Need confirmation on button label for checkout.}", "error_message": "none", // type code here for "relation_one" field }, ]; const SlackMessagesData = [ { // type code here for "relation_one" field // type code here for "relation_one" field "message_type": "notification", "delivery_status": "sent", "queued_at": new Date('2026-02-22T12:03:11Z'), "sent_at": new Date('2026-02-22T12:03:12Z'), "slack_ts": "1708603392.100100", "thread_ts": "1708603392.100100", "text": "Please create a hero image concept for the pricing page.", "blocks_json": "{type:mrkdwn,text:Please create a hero image concept for the pricing page.}", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "message_type": "reply", "delivery_status": "queued", "queued_at": new Date('2026-02-21T18:18:40Z'), "sent_at": new Date('2026-02-21T18:18:41Z'), "slack_ts": "1708549121.200200", "thread_ts": "1708549121.200200", "text": "Need updated diagram for onboarding flow.", "blocks_json": "{type:mrkdwn,text:Need updated diagram for onboarding flow.}", "error_message": "Slack API rate_limited", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "message_type": "reply", "delivery_status": "queued", "queued_at": new Date('2026-02-23T07:10:02Z'), "sent_at": new Date('2026-02-23T07:10:03Z'), "slack_ts": "1708672203.300300", "thread_ts": "1708672203.300300", "text": "Please review the summary for accuracy and add citations.", "blocks_json": "{type:mrkdwn,text:Please review the summary for accuracy and add citations.}", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "message_type": "request", "delivery_status": "sent", "queued_at": new Date('2026-02-24T09:38:21Z'), "sent_at": new Date('2026-02-24T09:38:22Z'), "slack_ts": "1708767502.400400", "thread_ts": "1708767502.400400", "text": "Can you approve the new product description draft by EOD?", "blocks_json": "{type:mrkdwn,text:Can you approve the new product description draft by EOD?}", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "message_type": "notification", "delivery_status": "queued", "queued_at": new Date('2026-02-20T10:22:02Z'), "sent_at": new Date('2026-02-20T10:22:02Z'), "slack_ts": "1708424522.500500", "thread_ts": "1708424522.500500", "text": "Need confirmation on button label for checkout.", "blocks_json": "{type:mrkdwn,text:Need confirmation on button label for checkout.}", "error_message": "none", // type code here for "relation_one" field }, ]; const HumanRepliesData = [ { // type code here for "relation_one" field "slack_user_id": "U024A1", "slack_user_name": "Sam Rivera", "reply_text": "I can draft two hero concepts today. Any preferred color palette?", // type code here for "files" field // type code here for "images" field "received_at": new Date('2026-02-22T12:10:00Z'), "processing_status": "failed", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field "slack_user_id": "U024N1", "slack_user_name": "Taylor Brooks", "reply_text": "Summary looks accurate. I will add two citations in the shared doc.", // type code here for "files" field // type code here for "images" field "received_at": new Date('2026-02-23T07:25:10Z'), "processing_status": "new", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field "slack_user_id": "U024C1", "slack_user_name": "Alex Morgan", "reply_text": "Approved. Please update the final paragraph to mention free returns.", // type code here for "files" field // type code here for "images" field "received_at": new Date('2026-02-24T10:05:30Z'), "processing_status": "acknowledged", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field "slack_user_id": "U024A2", "slack_user_name": "Jamie Lin", "reply_text": "Checkout button should be Continue to Payment for clarity.", // type code here for "files" field // type code here for "images" field "received_at": new Date('2026-02-20T10:40:12Z'), "processing_status": "failed", "error_message": "none", // type code here for "relation_one" field }, { // type code here for "relation_one" field "slack_user_id": "U024A3", "slack_user_name": "Priya Das", "reply_text": "I did not see the request in Slack. Can you resend once rate limits clear?", // type code here for "files" field // type code here for "images" field "received_at": new Date('2026-02-21T19:02:44Z'), "processing_status": "acknowledged", "error_message": "Original message failed to deliver", // type code here for "relation_one" field }, ]; const UploadsData = [ { // type code here for "relation_one" field // type code here for "relation_one" field "title": "Hero concept sketch v1", "upload_kind": "file", // type code here for "files" field // type code here for "images" field "content_type": "image/png", "size_bytes": 248192, "sha256": "9b7c4d2a0a1b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5", "visibility": "shared_with_agent", "available_until": new Date('2026-03-22T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "title": "Citation notes", "upload_kind": "file", // type code here for "files" field // type code here for "images" field "content_type": "application/pdf", "size_bytes": 102400, "sha256": "1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f809", "visibility": "private", "available_until": new Date('2026-03-10T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "title": "Revised product copy", "upload_kind": "file", // type code here for "files" field // type code here for "images" field "content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "size_bytes": 55296, "sha256": "2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a", "visibility": "shared_with_agent", "available_until": new Date('2026-03-01T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "title": "Checkout label rationale", "upload_kind": "file", // type code here for "files" field // type code here for "images" field "content_type": "text/plain", "size_bytes": 2048, "sha256": "3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b", "visibility": "private", "available_until": new Date('2026-04-01T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field // type code here for "relation_one" field "title": "Onboarding diagram draft", "upload_kind": "image", // type code here for "files" field // type code here for "images" field "content_type": "image/jpeg", "size_bytes": 331776, "sha256": "4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c", "visibility": "shared_with_agent", "available_until": new Date('2026-03-15T00:00:00Z'), // type code here for "relation_one" field }, ]; const WebhooksData = [ { // type code here for "relation_one" field "provider": "slack", "event_type": "reaction_added", "endpoint_path": "/webhooks/slack/events", "secret_hint": "whsec_acme", "status": "disabled", "last_received_at": new Date('2026-02-22T12:10:01Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "provider": "slack", "event_type": "message", "endpoint_path": "/webhooks/slack/events", "secret_hint": "whsec_nwind", "status": "enabled", "last_received_at": new Date('2026-02-23T07:25:11Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "provider": "slack", "event_type": "file_shared", "endpoint_path": "/webhooks/slack/events", "secret_hint": "whsec_cont", "status": "enabled", "last_received_at": new Date('2026-02-24T10:05:31Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "provider": "slack", "event_type": "app_mention", "endpoint_path": "/webhooks/slack/events", "secret_hint": "whsec_helios", "status": "enabled", "last_received_at": new Date('2026-01-20T12:09:59Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field "provider": "slack", "event_type": "app_mention", "endpoint_path": "/webhooks/slack/events", "secret_hint": "whsec_acme2", "status": "disabled", "last_received_at": new Date('2026-02-20T10:40:13Z'), // type code here for "relation_one" field }, ]; const AuditEventsData = [ { "event_type": "slack_message_sent", // type code here for "relation_one" field // type code here for "relation_one" field "subject": "Slack app installed", "details_json": "{team_id:T024ACME01,installed_by:Morgan Lee}", "occurred_at": new Date('2026-01-15T13:20:05Z'), // type code here for "relation_one" field }, { "event_type": "reply_received", // type code here for "relation_one" field // type code here for "relation_one" field "subject": "Channel registered", "details_json": "{channel:#design-ops,channel_id:C024ACME02}", "occurred_at": new Date('2026-01-16T09:05:00Z'), // type code here for "relation_one" field }, { "event_type": "slack_message_sent", // type code here for "relation_one" field // type code here for "relation_one" field "subject": "Agent client created", "details_json": "{name:UI Agent Prod,api_key_prefix:ak_ui_prod}", "occurred_at": new Date('2026-02-01T10:00:00Z'), // type code here for "relation_one" field }, { "event_type": "workspace_installed", // type code here for "relation_one" field // type code here for "relation_one" field "subject": "Slack send failed", "details_json": "{request_id:req_1d0c54e9,reason:rate_limited}", "occurred_at": new Date('2026-02-21T18:18:42Z'), // type code here for "relation_one" field }, { "event_type": "channel_updated", // type code here for "relation_one" field // type code here for "relation_one" field "subject": "Human reply received", "details_json": "{slack_user:Alex Morgan,thread_ts:1708767502.400400}", "occurred_at": new Date('2026-02-24T10:05:32Z'), // type code here for "relation_one" field }, ]; const AppSettingsData = [ { "key": "default_workspace", "value": "Acme Product Studio", "value_type": "secret", "description": "Workspace used when no workspace is specified", "scope": "workspace", // type code here for "relation_one" field "is_sensitive": true, // type code here for "relation_one" field }, { "key": "slack_signing_secret", "value": "env:SLACK_SIGNING_SECRET", "value_type": "json", "description": "Slack signing secret reference", "scope": "global", // type code here for "relation_one" field "is_sensitive": true, // type code here for "relation_one" field }, { "key": "mcp_base_url", "value": "https://mcp-notifier.example.com", "value_type": "secret", "description": "Public base URL for MCP server", "scope": "workspace", // type code here for "relation_one" field "is_sensitive": true, // type code here for "relation_one" field }, { "key": "default_channel_name", "value": "ai-requests", "value_type": "secret", "description": "Default Slack channel name for notifications", "scope": "global", // type code here for "relation_one" field "is_sensitive": false, // type code here for "relation_one" field }, { "key": "retention_days", "value": "30", "value_type": "secret", "description": "Default retention period for logs and uploads", "scope": "workspace", // type code here for "relation_one" field "is_sensitive": false, // 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 associateWorkspaceWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Workspace0 = await Workspaces.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Workspace0?.setOrganization) { await Workspace0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Workspace1 = await Workspaces.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Workspace1?.setOrganization) { await Workspace1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Workspace2 = await Workspaces.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Workspace2?.setOrganization) { await Workspace2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Workspace3 = await Workspaces.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Workspace3?.setOrganization) { await Workspace3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Workspace4 = await Workspaces.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Workspace4?.setOrganization) { await Workspace4. setOrganization(relatedOrganization4); } } async function associateSlackChannelWithWorkspace() { const relatedWorkspace0 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const SlackChannel0 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 0 }); if (SlackChannel0?.setWorkspace) { await SlackChannel0. setWorkspace(relatedWorkspace0); } const relatedWorkspace1 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const SlackChannel1 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 1 }); if (SlackChannel1?.setWorkspace) { await SlackChannel1. setWorkspace(relatedWorkspace1); } const relatedWorkspace2 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const SlackChannel2 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 2 }); if (SlackChannel2?.setWorkspace) { await SlackChannel2. setWorkspace(relatedWorkspace2); } const relatedWorkspace3 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const SlackChannel3 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 3 }); if (SlackChannel3?.setWorkspace) { await SlackChannel3. setWorkspace(relatedWorkspace3); } const relatedWorkspace4 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const SlackChannel4 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 4 }); if (SlackChannel4?.setWorkspace) { await SlackChannel4. setWorkspace(relatedWorkspace4); } } async function associateSlackChannelWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackChannel0 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 0 }); if (SlackChannel0?.setOrganization) { await SlackChannel0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackChannel1 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 1 }); if (SlackChannel1?.setOrganization) { await SlackChannel1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackChannel2 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 2 }); if (SlackChannel2?.setOrganization) { await SlackChannel2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackChannel3 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 3 }); if (SlackChannel3?.setOrganization) { await SlackChannel3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackChannel4 = await SlackChannels.findOne({ order: [['id', 'ASC']], offset: 4 }); if (SlackChannel4?.setOrganization) { await SlackChannel4. setOrganization(relatedOrganization4); } } async function associateAgentClientWithWorkspace() { const relatedWorkspace0 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AgentClient0 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AgentClient0?.setWorkspace) { await AgentClient0. setWorkspace(relatedWorkspace0); } const relatedWorkspace1 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AgentClient1 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AgentClient1?.setWorkspace) { await AgentClient1. setWorkspace(relatedWorkspace1); } const relatedWorkspace2 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AgentClient2 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AgentClient2?.setWorkspace) { await AgentClient2. setWorkspace(relatedWorkspace2); } const relatedWorkspace3 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AgentClient3 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AgentClient3?.setWorkspace) { await AgentClient3. setWorkspace(relatedWorkspace3); } const relatedWorkspace4 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AgentClient4 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AgentClient4?.setWorkspace) { await AgentClient4. setWorkspace(relatedWorkspace4); } } async function associateAgentClientWithDefault_channel() { const relatedDefault_channel0 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const AgentClient0 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AgentClient0?.setDefault_channel) { await AgentClient0. setDefault_channel(relatedDefault_channel0); } const relatedDefault_channel1 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const AgentClient1 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AgentClient1?.setDefault_channel) { await AgentClient1. setDefault_channel(relatedDefault_channel1); } const relatedDefault_channel2 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const AgentClient2 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AgentClient2?.setDefault_channel) { await AgentClient2. setDefault_channel(relatedDefault_channel2); } const relatedDefault_channel3 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const AgentClient3 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AgentClient3?.setDefault_channel) { await AgentClient3. setDefault_channel(relatedDefault_channel3); } const relatedDefault_channel4 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const AgentClient4 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AgentClient4?.setDefault_channel) { await AgentClient4. setDefault_channel(relatedDefault_channel4); } } async function associateAgentClientWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AgentClient0 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AgentClient0?.setOrganization) { await AgentClient0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AgentClient1 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AgentClient1?.setOrganization) { await AgentClient1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AgentClient2 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AgentClient2?.setOrganization) { await AgentClient2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AgentClient3 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AgentClient3?.setOrganization) { await AgentClient3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AgentClient4 = await AgentClients.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AgentClient4?.setOrganization) { await AgentClient4. setOrganization(relatedOrganization4); } } async function associateMcpToolCallWithAgent_client() { const relatedAgent_client0 = await AgentClients.findOne({ offset: Math.floor(Math.random() * (await AgentClients.count())), }); const McpToolCall0 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 0 }); if (McpToolCall0?.setAgent_client) { await McpToolCall0. setAgent_client(relatedAgent_client0); } const relatedAgent_client1 = await AgentClients.findOne({ offset: Math.floor(Math.random() * (await AgentClients.count())), }); const McpToolCall1 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 1 }); if (McpToolCall1?.setAgent_client) { await McpToolCall1. setAgent_client(relatedAgent_client1); } const relatedAgent_client2 = await AgentClients.findOne({ offset: Math.floor(Math.random() * (await AgentClients.count())), }); const McpToolCall2 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 2 }); if (McpToolCall2?.setAgent_client) { await McpToolCall2. setAgent_client(relatedAgent_client2); } const relatedAgent_client3 = await AgentClients.findOne({ offset: Math.floor(Math.random() * (await AgentClients.count())), }); const McpToolCall3 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 3 }); if (McpToolCall3?.setAgent_client) { await McpToolCall3. setAgent_client(relatedAgent_client3); } const relatedAgent_client4 = await AgentClients.findOne({ offset: Math.floor(Math.random() * (await AgentClients.count())), }); const McpToolCall4 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 4 }); if (McpToolCall4?.setAgent_client) { await McpToolCall4. setAgent_client(relatedAgent_client4); } } async function associateMcpToolCallWithWorkspace() { const relatedWorkspace0 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const McpToolCall0 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 0 }); if (McpToolCall0?.setWorkspace) { await McpToolCall0. setWorkspace(relatedWorkspace0); } const relatedWorkspace1 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const McpToolCall1 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 1 }); if (McpToolCall1?.setWorkspace) { await McpToolCall1. setWorkspace(relatedWorkspace1); } const relatedWorkspace2 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const McpToolCall2 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 2 }); if (McpToolCall2?.setWorkspace) { await McpToolCall2. setWorkspace(relatedWorkspace2); } const relatedWorkspace3 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const McpToolCall3 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 3 }); if (McpToolCall3?.setWorkspace) { await McpToolCall3. setWorkspace(relatedWorkspace3); } const relatedWorkspace4 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const McpToolCall4 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 4 }); if (McpToolCall4?.setWorkspace) { await McpToolCall4. setWorkspace(relatedWorkspace4); } } async function associateMcpToolCallWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const McpToolCall0 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 0 }); if (McpToolCall0?.setOrganization) { await McpToolCall0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const McpToolCall1 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 1 }); if (McpToolCall1?.setOrganization) { await McpToolCall1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const McpToolCall2 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 2 }); if (McpToolCall2?.setOrganization) { await McpToolCall2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const McpToolCall3 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 3 }); if (McpToolCall3?.setOrganization) { await McpToolCall3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const McpToolCall4 = await McpToolCalls.findOne({ order: [['id', 'ASC']], offset: 4 }); if (McpToolCall4?.setOrganization) { await McpToolCall4. setOrganization(relatedOrganization4); } } async function associateSlackMessageWithTool_call() { const relatedTool_call0 = await McpToolCalls.findOne({ offset: Math.floor(Math.random() * (await McpToolCalls.count())), }); const SlackMessage0 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 0 }); if (SlackMessage0?.setTool_call) { await SlackMessage0. setTool_call(relatedTool_call0); } const relatedTool_call1 = await McpToolCalls.findOne({ offset: Math.floor(Math.random() * (await McpToolCalls.count())), }); const SlackMessage1 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 1 }); if (SlackMessage1?.setTool_call) { await SlackMessage1. setTool_call(relatedTool_call1); } const relatedTool_call2 = await McpToolCalls.findOne({ offset: Math.floor(Math.random() * (await McpToolCalls.count())), }); const SlackMessage2 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 2 }); if (SlackMessage2?.setTool_call) { await SlackMessage2. setTool_call(relatedTool_call2); } const relatedTool_call3 = await McpToolCalls.findOne({ offset: Math.floor(Math.random() * (await McpToolCalls.count())), }); const SlackMessage3 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 3 }); if (SlackMessage3?.setTool_call) { await SlackMessage3. setTool_call(relatedTool_call3); } const relatedTool_call4 = await McpToolCalls.findOne({ offset: Math.floor(Math.random() * (await McpToolCalls.count())), }); const SlackMessage4 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 4 }); if (SlackMessage4?.setTool_call) { await SlackMessage4. setTool_call(relatedTool_call4); } } async function associateSlackMessageWithChannel() { const relatedChannel0 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const SlackMessage0 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 0 }); if (SlackMessage0?.setChannel) { await SlackMessage0. setChannel(relatedChannel0); } const relatedChannel1 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const SlackMessage1 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 1 }); if (SlackMessage1?.setChannel) { await SlackMessage1. setChannel(relatedChannel1); } const relatedChannel2 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const SlackMessage2 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 2 }); if (SlackMessage2?.setChannel) { await SlackMessage2. setChannel(relatedChannel2); } const relatedChannel3 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const SlackMessage3 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 3 }); if (SlackMessage3?.setChannel) { await SlackMessage3. setChannel(relatedChannel3); } const relatedChannel4 = await SlackChannels.findOne({ offset: Math.floor(Math.random() * (await SlackChannels.count())), }); const SlackMessage4 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 4 }); if (SlackMessage4?.setChannel) { await SlackMessage4. setChannel(relatedChannel4); } } async function associateSlackMessageWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackMessage0 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 0 }); if (SlackMessage0?.setOrganization) { await SlackMessage0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackMessage1 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 1 }); if (SlackMessage1?.setOrganization) { await SlackMessage1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackMessage2 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 2 }); if (SlackMessage2?.setOrganization) { await SlackMessage2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackMessage3 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 3 }); if (SlackMessage3?.setOrganization) { await SlackMessage3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const SlackMessage4 = await SlackMessages.findOne({ order: [['id', 'ASC']], offset: 4 }); if (SlackMessage4?.setOrganization) { await SlackMessage4. setOrganization(relatedOrganization4); } } async function associateHumanReplyWithMessage() { const relatedMessage0 = await SlackMessages.findOne({ offset: Math.floor(Math.random() * (await SlackMessages.count())), }); const HumanReply0 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 0 }); if (HumanReply0?.setMessage) { await HumanReply0. setMessage(relatedMessage0); } const relatedMessage1 = await SlackMessages.findOne({ offset: Math.floor(Math.random() * (await SlackMessages.count())), }); const HumanReply1 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 1 }); if (HumanReply1?.setMessage) { await HumanReply1. setMessage(relatedMessage1); } const relatedMessage2 = await SlackMessages.findOne({ offset: Math.floor(Math.random() * (await SlackMessages.count())), }); const HumanReply2 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 2 }); if (HumanReply2?.setMessage) { await HumanReply2. setMessage(relatedMessage2); } const relatedMessage3 = await SlackMessages.findOne({ offset: Math.floor(Math.random() * (await SlackMessages.count())), }); const HumanReply3 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 3 }); if (HumanReply3?.setMessage) { await HumanReply3. setMessage(relatedMessage3); } const relatedMessage4 = await SlackMessages.findOne({ offset: Math.floor(Math.random() * (await SlackMessages.count())), }); const HumanReply4 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 4 }); if (HumanReply4?.setMessage) { await HumanReply4. setMessage(relatedMessage4); } } async function associateHumanReplyWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HumanReply0 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 0 }); if (HumanReply0?.setOrganization) { await HumanReply0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HumanReply1 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 1 }); if (HumanReply1?.setOrganization) { await HumanReply1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HumanReply2 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 2 }); if (HumanReply2?.setOrganization) { await HumanReply2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HumanReply3 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 3 }); if (HumanReply3?.setOrganization) { await HumanReply3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const HumanReply4 = await HumanReplies.findOne({ order: [['id', 'ASC']], offset: 4 }); if (HumanReply4?.setOrganization) { await HumanReply4. setOrganization(relatedOrganization4); } } async function associateUploadWithWorkspace() { const relatedWorkspace0 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Upload0 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Upload0?.setWorkspace) { await Upload0. setWorkspace(relatedWorkspace0); } const relatedWorkspace1 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Upload1 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Upload1?.setWorkspace) { await Upload1. setWorkspace(relatedWorkspace1); } const relatedWorkspace2 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Upload2 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Upload2?.setWorkspace) { await Upload2. setWorkspace(relatedWorkspace2); } const relatedWorkspace3 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Upload3 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Upload3?.setWorkspace) { await Upload3. setWorkspace(relatedWorkspace3); } const relatedWorkspace4 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Upload4 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Upload4?.setWorkspace) { await Upload4. setWorkspace(relatedWorkspace4); } } async function associateUploadWithReply() { const relatedReply0 = await HumanReplies.findOne({ offset: Math.floor(Math.random() * (await HumanReplies.count())), }); const Upload0 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Upload0?.setReply) { await Upload0. setReply(relatedReply0); } const relatedReply1 = await HumanReplies.findOne({ offset: Math.floor(Math.random() * (await HumanReplies.count())), }); const Upload1 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Upload1?.setReply) { await Upload1. setReply(relatedReply1); } const relatedReply2 = await HumanReplies.findOne({ offset: Math.floor(Math.random() * (await HumanReplies.count())), }); const Upload2 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Upload2?.setReply) { await Upload2. setReply(relatedReply2); } const relatedReply3 = await HumanReplies.findOne({ offset: Math.floor(Math.random() * (await HumanReplies.count())), }); const Upload3 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Upload3?.setReply) { await Upload3. setReply(relatedReply3); } const relatedReply4 = await HumanReplies.findOne({ offset: Math.floor(Math.random() * (await HumanReplies.count())), }); const Upload4 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Upload4?.setReply) { await Upload4. setReply(relatedReply4); } } async function associateUploadWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Upload0 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Upload0?.setOrganization) { await Upload0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Upload1 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Upload1?.setOrganization) { await Upload1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Upload2 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Upload2?.setOrganization) { await Upload2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Upload3 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Upload3?.setOrganization) { await Upload3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Upload4 = await Uploads.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Upload4?.setOrganization) { await Upload4. setOrganization(relatedOrganization4); } } async function associateWebhookWithWorkspace() { const relatedWorkspace0 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Webhook0 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Webhook0?.setWorkspace) { await Webhook0. setWorkspace(relatedWorkspace0); } const relatedWorkspace1 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Webhook1 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Webhook1?.setWorkspace) { await Webhook1. setWorkspace(relatedWorkspace1); } const relatedWorkspace2 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Webhook2 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Webhook2?.setWorkspace) { await Webhook2. setWorkspace(relatedWorkspace2); } const relatedWorkspace3 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Webhook3 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Webhook3?.setWorkspace) { await Webhook3. setWorkspace(relatedWorkspace3); } const relatedWorkspace4 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const Webhook4 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Webhook4?.setWorkspace) { await Webhook4. setWorkspace(relatedWorkspace4); } } async function associateWebhookWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Webhook0 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 0 }); if (Webhook0?.setOrganization) { await Webhook0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Webhook1 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 1 }); if (Webhook1?.setOrganization) { await Webhook1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Webhook2 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 2 }); if (Webhook2?.setOrganization) { await Webhook2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Webhook3 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 3 }); if (Webhook3?.setOrganization) { await Webhook3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const Webhook4 = await Webhooks.findOne({ order: [['id', 'ASC']], offset: 4 }); if (Webhook4?.setOrganization) { await Webhook4. setOrganization(relatedOrganization4); } } async function associateAuditEventWithActor_user() { const relatedActor_user0 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent0 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AuditEvent0?.setActor_user) { await AuditEvent0. setActor_user(relatedActor_user0); } const relatedActor_user1 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent1 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AuditEvent1?.setActor_user) { await AuditEvent1. setActor_user(relatedActor_user1); } const relatedActor_user2 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent2 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AuditEvent2?.setActor_user) { await AuditEvent2. setActor_user(relatedActor_user2); } const relatedActor_user3 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent3 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AuditEvent3?.setActor_user) { await AuditEvent3. setActor_user(relatedActor_user3); } const relatedActor_user4 = await Users.findOne({ offset: Math.floor(Math.random() * (await Users.count())), }); const AuditEvent4 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AuditEvent4?.setActor_user) { await AuditEvent4. setActor_user(relatedActor_user4); } } async function associateAuditEventWithWorkspace() { const relatedWorkspace0 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AuditEvent0 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AuditEvent0?.setWorkspace) { await AuditEvent0. setWorkspace(relatedWorkspace0); } const relatedWorkspace1 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AuditEvent1 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AuditEvent1?.setWorkspace) { await AuditEvent1. setWorkspace(relatedWorkspace1); } const relatedWorkspace2 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AuditEvent2 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AuditEvent2?.setWorkspace) { await AuditEvent2. setWorkspace(relatedWorkspace2); } const relatedWorkspace3 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AuditEvent3 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AuditEvent3?.setWorkspace) { await AuditEvent3. setWorkspace(relatedWorkspace3); } const relatedWorkspace4 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AuditEvent4 = await AuditEvents.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AuditEvent4?.setWorkspace) { await AuditEvent4. setWorkspace(relatedWorkspace4); } } 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); } } async function associateAppSettingWithWorkspace() { const relatedWorkspace0 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AppSetting0 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AppSetting0?.setWorkspace) { await AppSetting0. setWorkspace(relatedWorkspace0); } const relatedWorkspace1 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AppSetting1 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AppSetting1?.setWorkspace) { await AppSetting1. setWorkspace(relatedWorkspace1); } const relatedWorkspace2 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AppSetting2 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AppSetting2?.setWorkspace) { await AppSetting2. setWorkspace(relatedWorkspace2); } const relatedWorkspace3 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AppSetting3 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AppSetting3?.setWorkspace) { await AppSetting3. setWorkspace(relatedWorkspace3); } const relatedWorkspace4 = await Workspaces.findOne({ offset: Math.floor(Math.random() * (await Workspaces.count())), }); const AppSetting4 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AppSetting4?.setWorkspace) { await AppSetting4. setWorkspace(relatedWorkspace4); } } async function associateAppSettingWithOrganization() { const relatedOrganization0 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSetting0 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 0 }); if (AppSetting0?.setOrganization) { await AppSetting0. setOrganization(relatedOrganization0); } const relatedOrganization1 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSetting1 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 1 }); if (AppSetting1?.setOrganization) { await AppSetting1. setOrganization(relatedOrganization1); } const relatedOrganization2 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSetting2 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 2 }); if (AppSetting2?.setOrganization) { await AppSetting2. setOrganization(relatedOrganization2); } const relatedOrganization3 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSetting3 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 3 }); if (AppSetting3?.setOrganization) { await AppSetting3. setOrganization(relatedOrganization3); } const relatedOrganization4 = await Organizations.findOne({ offset: Math.floor(Math.random() * (await Organizations.count())), }); const AppSetting4 = await AppSettings.findOne({ order: [['id', 'ASC']], offset: 4 }); if (AppSetting4?.setOrganization) { await AppSetting4. setOrganization(relatedOrganization4); } } module.exports = { up: async (queryInterface, Sequelize) => { await Organizations.bulkCreate(OrganizationsData); await Workspaces.bulkCreate(WorkspacesData); await SlackChannels.bulkCreate(SlackChannelsData); await AgentClients.bulkCreate(AgentClientsData); await McpToolCalls.bulkCreate(McpToolCallsData); await SlackMessages.bulkCreate(SlackMessagesData); await HumanReplies.bulkCreate(HumanRepliesData); await Uploads.bulkCreate(UploadsData); await Webhooks.bulkCreate(WebhooksData); await AuditEvents.bulkCreate(AuditEventsData); await AppSettings.bulkCreate(AppSettingsData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithOrganization(), await associateWorkspaceWithOrganization(), await associateSlackChannelWithWorkspace(), await associateSlackChannelWithOrganization(), await associateAgentClientWithWorkspace(), await associateAgentClientWithDefault_channel(), await associateAgentClientWithOrganization(), await associateMcpToolCallWithAgent_client(), await associateMcpToolCallWithWorkspace(), await associateMcpToolCallWithOrganization(), await associateSlackMessageWithTool_call(), await associateSlackMessageWithChannel(), await associateSlackMessageWithOrganization(), await associateHumanReplyWithMessage(), await associateHumanReplyWithOrganization(), await associateUploadWithWorkspace(), await associateUploadWithReply(), await associateUploadWithOrganization(), await associateWebhookWithWorkspace(), await associateWebhookWithOrganization(), await associateAuditEventWithActor_user(), await associateAuditEventWithWorkspace(), await associateAuditEventWithOrganization(), await associateAppSettingWithWorkspace(), await associateAppSettingWithOrganization(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('organizations', null, {}); await queryInterface.bulkDelete('workspaces', null, {}); await queryInterface.bulkDelete('slack_channels', null, {}); await queryInterface.bulkDelete('agent_clients', null, {}); await queryInterface.bulkDelete('mcp_tool_calls', null, {}); await queryInterface.bulkDelete('slack_messages', null, {}); await queryInterface.bulkDelete('human_replies', null, {}); await queryInterface.bulkDelete('uploads', null, {}); await queryInterface.bulkDelete('webhooks', null, {}); await queryInterface.bulkDelete('audit_events', null, {}); await queryInterface.bulkDelete('app_settings', null, {}); }, };