2425 lines
46 KiB
JavaScript
2425 lines
46 KiB
JavaScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const UserRoleAssignments = db.user_role_assignments;
|
|
|
|
const RolePermissionAssignments = db.role_permission_assignments;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const Conversations = db.conversations;
|
|
|
|
const Messages = db.messages;
|
|
|
|
const Templates = db.templates;
|
|
|
|
const AppInstances = db.app_instances;
|
|
|
|
const AuditEvents = db.audit_events;
|
|
|
|
const SystemSettings = db.system_settings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const UserRoleAssignmentsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"assigned_at": new Date('2026-01-06T10:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_primary": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"assigned_at": new Date('2026-01-11T09:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_primary": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"assigned_at": new Date('2026-01-13T12:15:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_primary": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const RolePermissionAssignmentsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"granted_at": new Date('2026-01-06T10:05:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"granted_at": new Date('2026-01-06T10:06:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"granted_at": new Date('2026-01-13T12:20:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ProjectsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Preview Workspace",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Sandbox workspace to validate templates and base CRUD capabilities.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "active",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-01-07T09:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"archived_at": new Date('2026-03-01T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "RBAC Hardening",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Review role assignments and tighten permissions for production readiness.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-01-15T10:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"archived_at": new Date('2026-03-05T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Template Catalog Refresh",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Curate a set of templates and improve metadata quality and release notes.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "active",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-02-01T11:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"archived_at": new Date('2026-04-01T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ConversationsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Project kickoff notes",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "closed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-02-10T09:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ended_at": new Date('2026-02-28T17:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Access review thread",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "open",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-02-12T14:20:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ended_at": new Date('2026-03-01T18:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Template feedback",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "open",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-02-18T11:10:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ended_at": new Date('2026-03-05T16:30:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const MessagesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"author_type": "system",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Kicking off the workspace setup. Please confirm the preferred template and initial roles.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-02-10T09:02:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"delivery_status": "failed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"author_type": "system",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Base CRUD is ready. Recommend starting with the fullstack template and enabling audit tracking.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-02-10T09:03:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"delivery_status": "pending",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"author_type": "assistant",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "I will review role assignments and ensure least privilege access for support and analysts.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-02-12T14:21:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"delivery_status": "sent",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const TemplatesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "React Node Fullstack Starter",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"type": "fullstack",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"frontend_stack": "react",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"backend_stack": "go",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "React and Node starter with authentication, RBAC, admin UI, and CRUD scaffolding.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"repository_url": "https://example.com/repos/react-node-starter",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"released_at": new Date('2026-01-02T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "React Admin UI Template",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"type": "fullstack",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"frontend_stack": "react",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"backend_stack": "go",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Frontend focused template with responsive admin layout and entity pages.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"repository_url": "https://example.com/repos/react-admin-ui",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"released_at": new Date('2026-01-10T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Node API Template",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"type": "backend",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"frontend_stack": "react",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"backend_stack": "python",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Node API template with Postgres integration, migrations, and RBAC middleware.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"repository_url": "https://example.com/repos/node-api-template",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"released_at": new Date('2026-01-12T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const AppInstancesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Preview Instance A",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "provisioning",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"frontend_url": "https://preview-a.example.com",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"backend_url": "https://api-preview-a.example.com",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"provisioned_at": new Date('2026-02-10T10:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"deleted_at_time": new Date('2026-04-01T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "RBAC Test Instance",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "provisioning",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"frontend_url": "https://rbac-test.example.com",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"backend_url": "https://api-rbac-test.example.com",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"provisioned_at": new Date('2026-02-12T16:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"deleted_at_time": new Date('2026-04-15T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Catalog Staging",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "deleted",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"frontend_url": "https://catalog-staging.example.com",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"backend_url": "https://api-catalog-staging.example.com",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"provisioned_at": new Date('2026-02-21T09:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"deleted_at_time": new Date('2026-05-01T00:00:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const AuditEventsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_type": "entity_created",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_name": "system_settings",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_reference": "auth.session_timeout_minutes",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"details": "Session timeout adjusted from 30 to 45 minutes.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "203.0.113.10",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Chrome on macOS",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"occurred_at": new Date('2026-02-08T12:05:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_type": "role_assigned",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_name": "user_role_assignments",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_reference": "assignment-0001",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"details": "Assigned Security Lead role to Diego Alvarez.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "198.51.100.22",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Firefox on Windows",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"occurred_at": new Date('2026-01-13T12:16:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"event_type": "entity_created",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_name": "projects",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entity_reference": "Template Catalog Refresh",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"details": "Created project to update template metadata and release cadence.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "203.0.113.44",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Chrome on Linux",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"occurred_at": new Date('2026-02-01T11:02:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const SystemSettingsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"key": "auth.session_timeout_minutes",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_type": "int",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_string": "45",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_boolean": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_int": 45,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_decimal": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Session timeout in minutes for authenticated users.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"key": "auth.require_email_verification",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_type": "boolean",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_string": "true",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_boolean": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_int": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_decimal": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Require users to verify email before gaining full access.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"key": "ui.default_frontend_stack",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_type": "boolean",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_string": "react",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_boolean": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_int": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"value_decimal": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Default frontend stack shown in template selection.",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateUserRoleAssignmentWithUser() {
|
|
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserRoleAssignment0 = await UserRoleAssignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (UserRoleAssignment0?.setUser)
|
|
{
|
|
await
|
|
UserRoleAssignment0.
|
|
setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserRoleAssignment1 = await UserRoleAssignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (UserRoleAssignment1?.setUser)
|
|
{
|
|
await
|
|
UserRoleAssignment1.
|
|
setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserRoleAssignment2 = await UserRoleAssignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (UserRoleAssignment2?.setUser)
|
|
{
|
|
await
|
|
UserRoleAssignment2.
|
|
setUser(relatedUser2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateRolePermissionAssignmentWithPermission() {
|
|
|
|
const relatedPermission0 = await Permissions.findOne({
|
|
offset: Math.floor(Math.random() * (await Permissions.count())),
|
|
});
|
|
const RolePermissionAssignment0 = await RolePermissionAssignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (RolePermissionAssignment0?.setPermission)
|
|
{
|
|
await
|
|
RolePermissionAssignment0.
|
|
setPermission(relatedPermission0);
|
|
}
|
|
|
|
const relatedPermission1 = await Permissions.findOne({
|
|
offset: Math.floor(Math.random() * (await Permissions.count())),
|
|
});
|
|
const RolePermissionAssignment1 = await RolePermissionAssignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (RolePermissionAssignment1?.setPermission)
|
|
{
|
|
await
|
|
RolePermissionAssignment1.
|
|
setPermission(relatedPermission1);
|
|
}
|
|
|
|
const relatedPermission2 = await Permissions.findOne({
|
|
offset: Math.floor(Math.random() * (await Permissions.count())),
|
|
});
|
|
const RolePermissionAssignment2 = await RolePermissionAssignments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (RolePermissionAssignment2?.setPermission)
|
|
{
|
|
await
|
|
RolePermissionAssignment2.
|
|
setPermission(relatedPermission2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateProjectWithOwner() {
|
|
|
|
const relatedOwner0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Project0 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Project0?.setOwner)
|
|
{
|
|
await
|
|
Project0.
|
|
setOwner(relatedOwner0);
|
|
}
|
|
|
|
const relatedOwner1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Project1 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Project1?.setOwner)
|
|
{
|
|
await
|
|
Project1.
|
|
setOwner(relatedOwner1);
|
|
}
|
|
|
|
const relatedOwner2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Project2 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Project2?.setOwner)
|
|
{
|
|
await
|
|
Project2.
|
|
setOwner(relatedOwner2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateConversationWithInitiator() {
|
|
|
|
const relatedInitiator0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Conversation0 = await Conversations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Conversation0?.setInitiator)
|
|
{
|
|
await
|
|
Conversation0.
|
|
setInitiator(relatedInitiator0);
|
|
}
|
|
|
|
const relatedInitiator1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Conversation1 = await Conversations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Conversation1?.setInitiator)
|
|
{
|
|
await
|
|
Conversation1.
|
|
setInitiator(relatedInitiator1);
|
|
}
|
|
|
|
const relatedInitiator2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Conversation2 = await Conversations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Conversation2?.setInitiator)
|
|
{
|
|
await
|
|
Conversation2.
|
|
setInitiator(relatedInitiator2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateMessageWithConversation() {
|
|
|
|
const relatedConversation0 = await Conversations.findOne({
|
|
offset: Math.floor(Math.random() * (await Conversations.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Message0?.setConversation)
|
|
{
|
|
await
|
|
Message0.
|
|
setConversation(relatedConversation0);
|
|
}
|
|
|
|
const relatedConversation1 = await Conversations.findOne({
|
|
offset: Math.floor(Math.random() * (await Conversations.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Message1?.setConversation)
|
|
{
|
|
await
|
|
Message1.
|
|
setConversation(relatedConversation1);
|
|
}
|
|
|
|
const relatedConversation2 = await Conversations.findOne({
|
|
offset: Math.floor(Math.random() * (await Conversations.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Message2?.setConversation)
|
|
{
|
|
await
|
|
Message2.
|
|
setConversation(relatedConversation2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateMessageWithAuthor() {
|
|
|
|
const relatedAuthor0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Message0?.setAuthor)
|
|
{
|
|
await
|
|
Message0.
|
|
setAuthor(relatedAuthor0);
|
|
}
|
|
|
|
const relatedAuthor1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Message1?.setAuthor)
|
|
{
|
|
await
|
|
Message1.
|
|
setAuthor(relatedAuthor1);
|
|
}
|
|
|
|
const relatedAuthor2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Message2?.setAuthor)
|
|
{
|
|
await
|
|
Message2.
|
|
setAuthor(relatedAuthor2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateAppInstanceWithProject() {
|
|
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const AppInstance0 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AppInstance0?.setProject)
|
|
{
|
|
await
|
|
AppInstance0.
|
|
setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const AppInstance1 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AppInstance1?.setProject)
|
|
{
|
|
await
|
|
AppInstance1.
|
|
setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const AppInstance2 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AppInstance2?.setProject)
|
|
{
|
|
await
|
|
AppInstance2.
|
|
setProject(relatedProject2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateAppInstanceWithTemplate() {
|
|
|
|
const relatedTemplate0 = await Templates.findOne({
|
|
offset: Math.floor(Math.random() * (await Templates.count())),
|
|
});
|
|
const AppInstance0 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AppInstance0?.setTemplate)
|
|
{
|
|
await
|
|
AppInstance0.
|
|
setTemplate(relatedTemplate0);
|
|
}
|
|
|
|
const relatedTemplate1 = await Templates.findOne({
|
|
offset: Math.floor(Math.random() * (await Templates.count())),
|
|
});
|
|
const AppInstance1 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AppInstance1?.setTemplate)
|
|
{
|
|
await
|
|
AppInstance1.
|
|
setTemplate(relatedTemplate1);
|
|
}
|
|
|
|
const relatedTemplate2 = await Templates.findOne({
|
|
offset: Math.floor(Math.random() * (await Templates.count())),
|
|
});
|
|
const AppInstance2 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AppInstance2?.setTemplate)
|
|
{
|
|
await
|
|
AppInstance2.
|
|
setTemplate(relatedTemplate2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateAppInstanceWithCreated_by_user() {
|
|
|
|
const relatedCreated_by_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AppInstance0 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AppInstance0?.setCreated_by_user)
|
|
{
|
|
await
|
|
AppInstance0.
|
|
setCreated_by_user(relatedCreated_by_user0);
|
|
}
|
|
|
|
const relatedCreated_by_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AppInstance1 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AppInstance1?.setCreated_by_user)
|
|
{
|
|
await
|
|
AppInstance1.
|
|
setCreated_by_user(relatedCreated_by_user1);
|
|
}
|
|
|
|
const relatedCreated_by_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AppInstance2 = await AppInstances.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AppInstance2?.setCreated_by_user)
|
|
{
|
|
await
|
|
AppInstance2.
|
|
setCreated_by_user(relatedCreated_by_user2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateAuditEventWithActor() {
|
|
|
|
const relatedActor0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AuditEvent0 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (AuditEvent0?.setActor)
|
|
{
|
|
await
|
|
AuditEvent0.
|
|
setActor(relatedActor0);
|
|
}
|
|
|
|
const relatedActor1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AuditEvent1 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (AuditEvent1?.setActor)
|
|
{
|
|
await
|
|
AuditEvent1.
|
|
setActor(relatedActor1);
|
|
}
|
|
|
|
const relatedActor2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const AuditEvent2 = await AuditEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (AuditEvent2?.setActor)
|
|
{
|
|
await
|
|
AuditEvent2.
|
|
setActor(relatedActor2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await UserRoleAssignments.bulkCreate(UserRoleAssignmentsData);
|
|
|
|
|
|
|
|
|
|
await RolePermissionAssignments.bulkCreate(RolePermissionAssignmentsData);
|
|
|
|
|
|
|
|
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
|
|
|
|
|
|
await Conversations.bulkCreate(ConversationsData);
|
|
|
|
|
|
|
|
|
|
await Messages.bulkCreate(MessagesData);
|
|
|
|
|
|
|
|
|
|
await Templates.bulkCreate(TemplatesData);
|
|
|
|
|
|
|
|
|
|
await AppInstances.bulkCreate(AppInstancesData);
|
|
|
|
|
|
|
|
|
|
await AuditEvents.bulkCreate(AuditEventsData);
|
|
|
|
|
|
|
|
|
|
await SystemSettings.bulkCreate(SystemSettingsData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateUserRoleAssignmentWithUser(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateRolePermissionAssignmentWithPermission(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateProjectWithOwner(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateConversationWithInitiator(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateMessageWithConversation(),
|
|
|
|
|
|
|
|
|
|
await associateMessageWithAuthor(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateAppInstanceWithProject(),
|
|
|
|
|
|
|
|
|
|
await associateAppInstanceWithTemplate(),
|
|
|
|
|
|
|
|
|
|
await associateAppInstanceWithCreated_by_user(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateAuditEventWithActor(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await queryInterface.bulkDelete('user_role_assignments', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('role_permission_assignments', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('conversations', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('messages', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('templates', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('app_instances', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('audit_events', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('system_settings', null, {});
|
|
|
|
|
|
},
|
|
}; |