





















const db = require('../models');
const Users = db.users;






const Organizations = db.organizations;

const Tenants = db.tenants;

const DataEntities = db.data_entities;

const ImportSources = db.import_sources;

const FileUploads = db.file_uploads;

const ImportJobs = db.import_jobs;

const ImportMappings = db.import_mappings;

const MappingRules = db.mapping_rules;

const ValidationRuleSets = db.validation_rule_sets;

const ValidationRules = db.validation_rules;

const ImportRowResults = db.import_row_results;

const ImportIssues = db.import_issues;

const ImportTemplates = db.import_templates;

const Products = db.products;

const Customers = db.customers;

const Suppliers = db.suppliers;

const AvailabilityRecords = db.availability_records;

const AuditEvents = db.audit_events;







const OrganizationsData = [
    
    {
    
        
        
            
                "name": "Grace Hopper",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Grace Hopper",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Ada Lovelace",
            
        
    
    },
    
    {
    
        
        
            
                "name": "Grace Hopper",
            
        
    
    },
    
];



const TenantsData = [
    
    {
    
        
        
            
                "name": "Northwind Distribution",
            
        
    
        
        
            
                "slug": "northwind-distribution",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "onboarded_at": new Date('2025-01-15T10:00:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Contoso Retail Group",
            
        
    
        
        
            
                "slug": "contoso-retail-group",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "onboarded_at": new Date('2025-02-03T09:30:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Fabrikam Manufacturing",
            
        
    
        
        
            
                "slug": "fabrikam-manufacturing",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "onboarded_at": new Date('2025-03-12T14:15:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Adventure Works Logistics",
            
        
    
        
        
            
                "slug": "adventure-works-logistics",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "onboarded_at": new Date('2025-04-01T08:45:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const DataEntitiesData = [
    
    {
    
        
        
            
                "name": "Products",
            
        
    
        
        
            
                "code": "products",
            
        
    
        
        
            
                "description": "Master data for items sold or stocked",
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Customers",
            
        
    
        
        
            
                "code": "customers",
            
        
    
        
        
            
                "description": "Customer accounts and contact details",
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Suppliers",
            
        
    
        
        
            
                "code": "suppliers",
            
        
    
        
        
            
                "description": "Supplier accounts and contact details",
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Availability",
            
        
    
        
        
            
                "code": "availability",
            
        
    
        
        
            
                "description": "Inventory availability snapshots by location",
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ImportSourcesData = [
    
    {
    
        
        
            
                "name": "Default CSV Upload",
            
        
    
        
        
            
                "source_type": "csv",
            
        
    
        
        
            
                "notes": "Standard CSV uploads from customer operators",
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Excel Upload",
            
        
    
        
        
            
                "source_type": "csv",
            
        
    
        
        
            
                "notes": "Excel uploads with header row in first sheet",
            
        
    
        
        
            
                "is_default": false,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Legacy XLS Upload",
            
        
    
        
        
            
                "source_type": "csv",
            
        
    
        
        
            
                "notes": "Legacy XLS from older export tools",
            
        
    
        
        
            
                "is_default": false,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                "name": "Nightly Vendor Feed",
            
        
    
        
        
            
                "source_type": "xls",
            
        
    
        
        
            
                "notes": "Scheduled file drop processed manually for now",
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const FileUploadsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "original_filename": "northwind_products_2025_02.csv",
            
        
    
        
        
            
                "content_type": "text/csv",
            
        
    
        
        
            
                "size_bytes": 248120,
            
        
    
        
        
            
                "checksum_sha256": "8f0d2b6a1c4f7e9b0a1d2c3b4e5f60718293a4b5c6d7e8f90123456789abcdef",
            
        
    
        
        
            
                "uploaded_at": new Date('2025-02-10T11:05:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "original_filename": "northwind_customers_2025_02.xlsx",
            
        
    
        
        
            
                "content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            
        
    
        
        
            
                "size_bytes": 512330,
            
        
    
        
        
            
                "checksum_sha256": "1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f809",
            
        
    
        
        
            
                "uploaded_at": new Date('2025-02-11T09:20:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "original_filename": "contoso_suppliers_q1.csv",
            
        
    
        
        
            
                "content_type": "text/csv",
            
        
    
        
        
            
                "size_bytes": 18240,
            
        
    
        
        
            
                "checksum_sha256": "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789",
            
        
    
        
        
            
                "uploaded_at": new Date('2025-03-05T15:42:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "original_filename": "contoso_availability_week10.xlsx",
            
        
    
        
        
            
                "content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            
        
    
        
        
            
                "size_bytes": 734210,
            
        
    
        
        
            
                "checksum_sha256": "0f1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c4b5a69788796a5b4c3d2e1f0",
            
        
    
        
        
            
                "uploaded_at": new Date('2025-03-08T07:55:00Z'),
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ImportJobsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "validation_failed",
            
        
    
        
        
            
                "started_at": new Date('2025-02-10T11:06:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2025-02-10T11:09:10Z'),
            
        
    
        
        
            
                "total_rows": 1200,
            
        
    
        
        
            
                "valid_rows": 1184,
            
        
    
        
        
            
                "invalid_rows": 16,
            
        
    
        
        
            
                "warning_rows": 34,
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "job_name": "Northwind Products Feb Load",
            
        
    
        
        
            
                "notes": "Monthly products refresh",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "validating",
            
        
    
        
        
            
                "started_at": new Date('2025-02-11T09:22:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2025-02-11T09:24:30Z'),
            
        
    
        
        
            
                "total_rows": 450,
            
        
    
        
        
            
                "valid_rows": 410,
            
        
    
        
        
            
                "invalid_rows": 40,
            
        
    
        
        
            
                "warning_rows": 12,
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "job_name": "Northwind Customers Feb Load",
            
        
    
        
        
            
                "notes": "Validation failed due to missing customer codes",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "draft",
            
        
    
        
        
            
                "started_at": new Date('2025-03-05T15:43:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2025-03-05T15:47:00Z'),
            
        
    
        
        
            
                "total_rows": 85,
            
        
    
        
        
            
                "valid_rows": 85,
            
        
    
        
        
            
                "invalid_rows": 0,
            
        
    
        
        
            
                "warning_rows": 3,
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "job_name": "Contoso Suppliers Q1",
            
        
    
        
        
            
                "notes": "Import failed due to database timeout",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "importing",
            
        
    
        
        
            
                "started_at": new Date('2025-03-08T07:56:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2025-03-08T08:02:20Z'),
            
        
    
        
        
            
                "total_rows": 3200,
            
        
    
        
        
            
                "valid_rows": 3190,
            
        
    
        
        
            
                "invalid_rows": 10,
            
        
    
        
        
            
                "warning_rows": 120,
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "job_name": "Contoso Availability Week 10",
            
        
    
        
        
            
                "notes": "Ready after minor corrections",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ImportMappingsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Products Standard Mapping",
            
        
    
        
        
            
                "description": "Maps common product columns to ERP product fields",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Customers Standard Mapping",
            
        
    
        
        
            
                "description": "Maps customer file columns including addresses",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Suppliers Standard Mapping",
            
        
    
        
        
            
                "description": "Maps supplier master columns",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Availability Location Snapshot",
            
        
    
        
        
            
                "description": "Maps location and quantities for availability records",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const MappingRulesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "source_column": "SKU",
            
        
    
        
        
            
                "target_field": "sku",
            
        
    
        
        
            
                "transform_type": "number_parse",
            
        
    
        
        
            
                "transform_config": "{}",
            
        
    
        
        
            
                "is_required": true,
            
        
    
        
        
            
                "order_index": 1,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "source_column": "Product Name",
            
        
    
        
        
            
                "target_field": "name",
            
        
    
        
        
            
                "transform_type": "lookup",
            
        
    
        
        
            
                "transform_config": "{}",
            
        
    
        
        
            
                "is_required": true,
            
        
    
        
        
            
                "order_index": 2,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "source_column": "Status",
            
        
    
        
        
            
                "target_field": "status",
            
        
    
        
        
            
                "transform_type": "none",
            
        
    
        
        
            
                "transform_config": "{}",
            
        
    
        
        
            
                "is_required": true,
            
        
    
        
        
            
                "order_index": 3,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "source_column": "Price",
            
        
    
        
        
            
                "target_field": "price",
            
        
    
        
        
            
                "transform_type": "trim",
            
        
    
        
        
            
                "transform_config": "{decimalSeparator: .}",
            
        
    
        
        
            
                "is_required": true,
            
        
    
        
        
            
                "order_index": 4,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ValidationRuleSetsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Products Default Rules",
            
        
    
        
        
            
                "description": "Baseline product validation rules for required fields and formats",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Customers Default Rules",
            
        
    
        
        
            
                "description": "Baseline customer validation including required code and email format",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Suppliers Default Rules",
            
        
    
        
        
            
                "description": "Baseline supplier validation including required supplier code",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Availability Default Rules",
            
        
    
        
        
            
                "description": "Baseline availability validation for location and quantities",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "is_default": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ValidationRulesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "SKU required",
            
        
    
        
        
            
                "severity": "error",
            
        
    
        
        
            
                "rule_type": "format",
            
        
    
        
        
            
                "target_field": "sku",
            
        
    
        
        
            
                "condition_expression": "true",
            
        
    
        
        
            
                "parameters": "{}",
            
        
    
        
        
            
                "message_template": "SKU is required",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "order_index": 1,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "SKU unique",
            
        
    
        
        
            
                "severity": "warning",
            
        
    
        
        
            
                "rule_type": "custom_expression",
            
        
    
        
        
            
                "target_field": "sku",
            
        
    
        
        
            
                "condition_expression": "true",
            
        
    
        
        
            
                "parameters": "{scope:tenant}",
            
        
    
        
        
            
                "message_template": "SKU must be unique",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "order_index": 2,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Email format",
            
        
    
        
        
            
                "severity": "warning",
            
        
    
        
        
            
                "rule_type": "enum_in",
            
        
    
        
        
            
                "target_field": "email",
            
        
    
        
        
            
                "condition_expression": "true",
            
        
    
        
        
            
                "parameters": "{pattern:^\\S+@\\S+\\.\\S+$}",
            
        
    
        
        
            
                "message_template": "Email must be a valid address",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "order_index": 3,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Quantity non negative",
            
        
    
        
        
            
                "severity": "warning",
            
        
    
        
        
            
                "rule_type": "range",
            
        
    
        
        
            
                "target_field": "quantity_available",
            
        
    
        
        
            
                "condition_expression": "true",
            
        
    
        
        
            
                "parameters": "{min:0}",
            
        
    
        
        
            
                "message_template": "Quantity available cannot be negative",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                "order_index": 4,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ImportRowResultsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "row_number": 2,
            
        
    
        
        
            
                "status": "skipped",
            
        
    
        
        
            
                "raw_row": "{SKU:,Product Name:Widget A,Status:ACTIVE}",
            
        
    
        
        
            
                "normalized_row": "{sku:null,name:Widget A,status:active}",
            
        
    
        
        
            
                "primary_key_hint": "sku:",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "row_number": 15,
            
        
    
        
        
            
                "status": "invalid",
            
        
    
        
        
            
                "raw_row": "{SKU:NW-1005,Product Name:Gadget Pro,Status:ACTIVE,Currency:usd}",
            
        
    
        
        
            
                "normalized_row": "{sku:NW-1005,name:Gadget Pro,status:active,currency:USD}",
            
        
    
        
        
            
                "primary_key_hint": "sku:NW-1005",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "row_number": 33,
            
        
    
        
        
            
                "status": "warning",
            
        
    
        
        
            
                "raw_row": "{Customer Code:C-0042,Customer Name:Acme Stores,Email:orders@acmestores.example}",
            
        
    
        
        
            
                "normalized_row": "{customer_code:C-0042,name:Acme Stores,email:orders@acmestores.example}",
            
        
    
        
        
            
                "primary_key_hint": "customer_code:C-0042",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "row_number": 108,
            
        
    
        
        
            
                "status": "skipped",
            
        
    
        
        
            
                "raw_row": "{Location Code:SEA,Product SKU:NW-1005,Quantity Available:-3,As Of:2025-03-08}",
            
        
    
        
        
            
                "normalized_row": "{location_code:SEA,product_sku:NW-1005,quantity_available:-3,as_of:2025-03-08T00:00:00Z}",
            
        
    
        
        
            
                "primary_key_hint": "location:SEA sku:NW-1005",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ImportIssuesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "severity": "warning",
            
        
    
        
        
            
                "field_name": "sku",
            
        
    
        
        
            
                "message": "SKU is required",
            
        
    
        
        
            
                "details": "{rule:required}",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "severity": "error",
            
        
    
        
        
            
                "field_name": "currency",
            
        
    
        
        
            
                "message": "Currency was normalized to uppercase",
            
        
    
        
        
            
                "details": "{from:usd,to:USD}",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "severity": "error",
            
        
    
        
        
            
                "field_name": "quantity_available",
            
        
    
        
        
            
                "message": "Quantity available cannot be negative",
            
        
    
        
        
            
                "details": "{min:0,actual:-3}",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "severity": "error",
            
        
    
        
        
            
                "field_name": "email",
            
        
    
        
        
            
                "message": "Email must be a valid address",
            
        
    
        
        
            
                "details": "{value:orders-at-acme}",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ImportTemplatesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Products CSV Template",
            
        
    
        
        
            
                "file_type": "xlsx",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "description": "CSV template for product imports with common fields",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Customers Excel Template",
            
        
    
        
        
            
                "file_type": "xlsx",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "description": "Excel template for customer imports including addresses",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Suppliers CSV Template",
            
        
    
        
        
            
                "file_type": "xls",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "description": "CSV template for supplier imports",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Availability Excel Template",
            
        
    
        
        
            
                "file_type": "xls",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "description": "Excel template for availability snapshots",
            
        
    
        
        
            
                "is_active": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const ProductsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "sku": "NW-1001",
            
        
    
        
        
            
                "name": "Standard Widget",
            
        
    
        
        
            
                "description": "General purpose widget for assembly",
            
        
    
        
        
            
                "status": "discontinued",
            
        
    
        
        
            
                "uom": "EA",
            
        
    
        
        
            
                "price": 12.5,
            
        
    
        
        
            
                "currency": "USD",
            
        
    
        
        
            
                "is_stocked": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "sku": "NW-1002",
            
        
    
        
        
            
                "name": "Widget Plus",
            
        
    
        
        
            
                "description": "Upgraded widget with reinforced casing",
            
        
    
        
        
            
                "status": "inactive",
            
        
    
        
        
            
                "uom": "EA",
            
        
    
        
        
            
                "price": 18.0,
            
        
    
        
        
            
                "currency": "USD",
            
        
    
        
        
            
                "is_stocked": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "sku": "NW-2001",
            
        
    
        
        
            
                "name": "Gadget Basic",
            
        
    
        
        
            
                "description": "Entry level gadget for everyday use",
            
        
    
        
        
            
                "status": "inactive",
            
        
    
        
        
            
                "uom": "EA",
            
        
    
        
        
            
                "price": 9.99,
            
        
    
        
        
            
                "currency": "USD",
            
        
    
        
        
            
                "is_stocked": true,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "sku": "CT-3005",
            
        
    
        
        
            
                "name": "Retail Display Stand",
            
        
    
        
        
            
                "description": "Floor stand for in store product displays",
            
        
    
        
        
            
                "status": "inactive",
            
        
    
        
        
            
                "uom": "EA",
            
        
    
        
        
            
                "price": 75.0,
            
        
    
        
        
            
                "currency": "USD",
            
        
    
        
        
            
                "is_stocked": false,
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const CustomersData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "customer_code": "C-0001",
            
        
    
        
        
            
                "name": "Acme Stores",
            
        
    
        
        
            
                "email": "orders@acmestores.example",
            
        
    
        
        
            
                "phone": "+1 206 555 0134",
            
        
    
        
        
            
                "billing_address": "1200 Market St Seattle WA 98101",
            
        
    
        
        
            
                "shipping_address": "1200 Market St Seattle WA 98101",
            
        
    
        
        
            
                "status": "inactive",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "customer_code": "C-0002",
            
        
    
        
        
            
                "name": "Evergreen Outfitters",
            
        
    
        
        
            
                "email": "purchasing@evergreenoutfitters.example",
            
        
    
        
        
            
                "phone": "+1 425 555 0199",
            
        
    
        
        
            
                "billing_address": "88 Pine Ave Bellevue WA 98004",
            
        
    
        
        
            
                "shipping_address": "44 Cedar Rd Bellevue WA 98005",
            
        
    
        
        
            
                "status": "inactive",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "customer_code": "C-0003",
            
        
    
        
        
            
                "name": "Lakeview Hardware",
            
        
    
        
        
            
                "email": "ap@lakeviewhardware.example",
            
        
    
        
        
            
                "phone": "+1 503 555 0107",
            
        
    
        
        
            
                "billing_address": "15 River St Portland OR 97204",
            
        
    
        
        
            
                "shipping_address": "15 River St Portland OR 97204",
            
        
    
        
        
            
                "status": "active",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "customer_code": "C-0004",
            
        
    
        
        
            
                "name": "Summit Office Supply",
            
        
    
        
        
            
                "email": "orders@summitoffice.example",
            
        
    
        
        
            
                "phone": "+1 415 555 0122",
            
        
    
        
        
            
                "billing_address": "200 Mission St San Francisco CA 94105",
            
        
    
        
        
            
                "shipping_address": "210 Mission St San Francisco CA 94105",
            
        
    
        
        
            
                "status": "active",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const SuppliersData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "supplier_code": "S-001",
            
        
    
        
        
            
                "name": "Pacific Components",
            
        
    
        
        
            
                "email": "sales@pacificcomponents.example",
            
        
    
        
        
            
                "phone": "+1 408 555 0144",
            
        
    
        
        
            
                "address": "700 Innovation Dr San Jose CA 95110",
            
        
    
        
        
            
                "status": "inactive",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "supplier_code": "S-002",
            
        
    
        
        
            
                "name": "Cascade Packaging",
            
        
    
        
        
            
                "email": "orders@cascadepackaging.example",
            
        
    
        
        
            
                "phone": "+1 503 555 0161",
            
        
    
        
        
            
                "address": "55 Industrial Way Portland OR 97210",
            
        
    
        
        
            
                "status": "inactive",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "supplier_code": "S-003",
            
        
    
        
        
            
                "name": "Metro Industrial Supply",
            
        
    
        
        
            
                "email": "support@metroindustrial.example",
            
        
    
        
        
            
                "phone": "+1 312 555 0180",
            
        
    
        
        
            
                "address": "300 Lake St Chicago IL 60601",
            
        
    
        
        
            
                "status": "active",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "supplier_code": "S-004",
            
        
    
        
        
            
                "name": "Northeast Freight Partners",
            
        
    
        
        
            
                "email": "dispatch@nefreight.example",
            
        
    
        
        
            
                "phone": "+1 617 555 0111",
            
        
    
        
        
            
                "address": "12 Harbor Rd Boston MA 02110",
            
        
    
        
        
            
                "status": "active",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const AvailabilityRecordsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "location_code": "SEA",
            
        
    
        
        
            
                "product_sku": "NW-1001",
            
        
    
        
        
            
                "quantity_on_hand": 250,
            
        
    
        
        
            
                "quantity_available": 240,
            
        
    
        
        
            
                "as_of": new Date('2025-03-08T00:00:00Z'),
            
        
    
        
        
            
                "source_reference": "W10-SEA-NW-1001",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "location_code": "SEA",
            
        
    
        
        
            
                "product_sku": "NW-1002",
            
        
    
        
        
            
                "quantity_on_hand": 120,
            
        
    
        
        
            
                "quantity_available": 118,
            
        
    
        
        
            
                "as_of": new Date('2025-03-08T00:00:00Z'),
            
        
    
        
        
            
                "source_reference": "W10-SEA-NW-1002",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "location_code": "PDX",
            
        
    
        
        
            
                "product_sku": "NW-2001",
            
        
    
        
        
            
                "quantity_on_hand": 80,
            
        
    
        
        
            
                "quantity_available": 75,
            
        
    
        
        
            
                "as_of": new Date('2025-03-08T00:00:00Z'),
            
        
    
        
        
            
                "source_reference": "W10-PDX-NW-2001",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "location_code": "SFO",
            
        
    
        
        
            
                "product_sku": "CT-3005",
            
        
    
        
        
            
                "quantity_on_hand": 10,
            
        
    
        
        
            
                "quantity_available": 8,
            
        
    
        
        
            
                "as_of": new Date('2025-03-08T00:00:00Z'),
            
        
    
        
        
            
                "source_reference": "W10-SFO-CT-3005",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
];



const AuditEventsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "event_type": "logout",
            
        
    
        
        
            
                "entity_name": "file_uploads",
            
        
    
        
        
            
                "entity_key": "northwind_products_2025_02.csv",
            
        
    
        
        
            
                "event_at": new Date('2025-02-10T11:05:10Z'),
            
        
    
        
        
            
                "metadata": "{ip:203.0.113.10,userAgent:Chrome}",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "event_type": "template_downloaded",
            
        
    
        
        
            
                "entity_name": "import_jobs",
            
        
    
        
        
            
                "entity_key": "Northwind Products Feb Load",
            
        
    
        
        
            
                "event_at": new Date('2025-02-10T11:05:50Z'),
            
        
    
        
        
            
                "metadata": "{entity:products}",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "event_type": "login",
            
        
    
        
        
            
                "entity_name": "import_jobs",
            
        
    
        
        
            
                "entity_key": "Northwind Customers Feb Load",
            
        
    
        
        
            
                "event_at": new Date('2025-02-11T09:24:20Z'),
            
        
    
        
        
            
                "metadata": "{status:validation_failed}",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "event_type": "logout",
            
        
    
        
        
            
                "entity_name": "import_mappings",
            
        
    
        
        
            
                "entity_key": "Products Standard Mapping",
            
        
    
        
        
            
                "event_at": new Date('2025-03-01T12:00:00Z'),
            
        
    
        
        
            
                "metadata": "{change:updated mapping rules}",
            
        
    
        
        
            
                // 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);
                }
            
        }
        
    

    
    
    
    
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
            
            async function associateTenantWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Tenant0 = await Tenants.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Tenant0?.setOrganization)
                {
                    await
                    Tenant0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Tenant1 = await Tenants.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Tenant1?.setOrganization)
                {
                    await
                    Tenant1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Tenant2 = await Tenants.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Tenant2?.setOrganization)
                {
                    await
                    Tenant2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Tenant3 = await Tenants.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Tenant3?.setOrganization)
                {
                    await
                    Tenant3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    
        
    
        
            
            async function associateDataEntityWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const DataEntity0 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (DataEntity0?.setTenant)
                {
                    await
                    DataEntity0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const DataEntity1 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (DataEntity1?.setTenant)
                {
                    await
                    DataEntity1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const DataEntity2 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (DataEntity2?.setTenant)
                {
                    await
                    DataEntity2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const DataEntity3 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (DataEntity3?.setTenant)
                {
                    await
                    DataEntity3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            async function associateDataEntityWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const DataEntity0 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (DataEntity0?.setOrganization)
                {
                    await
                    DataEntity0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const DataEntity1 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (DataEntity1?.setOrganization)
                {
                    await
                    DataEntity1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const DataEntity2 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (DataEntity2?.setOrganization)
                {
                    await
                    DataEntity2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const DataEntity3 = await DataEntities.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (DataEntity3?.setOrganization)
                {
                    await
                    DataEntity3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
    
        
    
        
    
        
    
        
            
            async function associateImportSourceWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportSource0 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportSource0?.setTenant)
                {
                    await
                    ImportSource0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportSource1 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportSource1?.setTenant)
                {
                    await
                    ImportSource1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportSource2 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportSource2?.setTenant)
                {
                    await
                    ImportSource2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportSource3 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportSource3?.setTenant)
                {
                    await
                    ImportSource3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            async function associateImportSourceWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportSource0 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportSource0?.setOrganization)
                {
                    await
                    ImportSource0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportSource1 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportSource1?.setOrganization)
                {
                    await
                    ImportSource1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportSource2 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportSource2?.setOrganization)
                {
                    await
                    ImportSource2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportSource3 = await ImportSources.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportSource3?.setOrganization)
                {
                    await
                    ImportSource3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateFileUploadWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const FileUpload0 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (FileUpload0?.setTenant)
                {
                    await
                    FileUpload0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const FileUpload1 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (FileUpload1?.setTenant)
                {
                    await
                    FileUpload1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const FileUpload2 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (FileUpload2?.setTenant)
                {
                    await
                    FileUpload2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const FileUpload3 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (FileUpload3?.setTenant)
                {
                    await
                    FileUpload3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            async function associateFileUploadWithUploaded_by() {
            
                const relatedUploaded_by0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const FileUpload0 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (FileUpload0?.setUploaded_by)
                {
                    await
                    FileUpload0.
                    setUploaded_by(relatedUploaded_by0);
                }
            
                const relatedUploaded_by1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const FileUpload1 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (FileUpload1?.setUploaded_by)
                {
                    await
                    FileUpload1.
                    setUploaded_by(relatedUploaded_by1);
                }
            
                const relatedUploaded_by2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const FileUpload2 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (FileUpload2?.setUploaded_by)
                {
                    await
                    FileUpload2.
                    setUploaded_by(relatedUploaded_by2);
                }
            
                const relatedUploaded_by3 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const FileUpload3 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (FileUpload3?.setUploaded_by)
                {
                    await
                    FileUpload3.
                    setUploaded_by(relatedUploaded_by3);
                }
            
        }
        
    
        
            
            async function associateFileUploadWithSource() {
            
                const relatedSource0 = await ImportSources.findOne({
                    offset: Math.floor(Math.random() * (await ImportSources.count())),
                });
                const FileUpload0 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (FileUpload0?.setSource)
                {
                    await
                    FileUpload0.
                    setSource(relatedSource0);
                }
            
                const relatedSource1 = await ImportSources.findOne({
                    offset: Math.floor(Math.random() * (await ImportSources.count())),
                });
                const FileUpload1 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (FileUpload1?.setSource)
                {
                    await
                    FileUpload1.
                    setSource(relatedSource1);
                }
            
                const relatedSource2 = await ImportSources.findOne({
                    offset: Math.floor(Math.random() * (await ImportSources.count())),
                });
                const FileUpload2 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (FileUpload2?.setSource)
                {
                    await
                    FileUpload2.
                    setSource(relatedSource2);
                }
            
                const relatedSource3 = await ImportSources.findOne({
                    offset: Math.floor(Math.random() * (await ImportSources.count())),
                });
                const FileUpload3 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (FileUpload3?.setSource)
                {
                    await
                    FileUpload3.
                    setSource(relatedSource3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateFileUploadWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const FileUpload0 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (FileUpload0?.setOrganization)
                {
                    await
                    FileUpload0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const FileUpload1 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (FileUpload1?.setOrganization)
                {
                    await
                    FileUpload1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const FileUpload2 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (FileUpload2?.setOrganization)
                {
                    await
                    FileUpload2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const FileUpload3 = await FileUploads.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (FileUpload3?.setOrganization)
                {
                    await
                    FileUpload3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateImportJobWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportJob0 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportJob0?.setTenant)
                {
                    await
                    ImportJob0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportJob1 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportJob1?.setTenant)
                {
                    await
                    ImportJob1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportJob2 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportJob2?.setTenant)
                {
                    await
                    ImportJob2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportJob3 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportJob3?.setTenant)
                {
                    await
                    ImportJob3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            async function associateImportJobWithRequested_by() {
            
                const relatedRequested_by0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ImportJob0 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportJob0?.setRequested_by)
                {
                    await
                    ImportJob0.
                    setRequested_by(relatedRequested_by0);
                }
            
                const relatedRequested_by1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ImportJob1 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportJob1?.setRequested_by)
                {
                    await
                    ImportJob1.
                    setRequested_by(relatedRequested_by1);
                }
            
                const relatedRequested_by2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ImportJob2 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportJob2?.setRequested_by)
                {
                    await
                    ImportJob2.
                    setRequested_by(relatedRequested_by2);
                }
            
                const relatedRequested_by3 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ImportJob3 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportJob3?.setRequested_by)
                {
                    await
                    ImportJob3.
                    setRequested_by(relatedRequested_by3);
                }
            
        }
        
    
        
            
            async function associateImportJobWithData_entity() {
            
                const relatedData_entity0 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportJob0 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportJob0?.setData_entity)
                {
                    await
                    ImportJob0.
                    setData_entity(relatedData_entity0);
                }
            
                const relatedData_entity1 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportJob1 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportJob1?.setData_entity)
                {
                    await
                    ImportJob1.
                    setData_entity(relatedData_entity1);
                }
            
                const relatedData_entity2 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportJob2 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportJob2?.setData_entity)
                {
                    await
                    ImportJob2.
                    setData_entity(relatedData_entity2);
                }
            
                const relatedData_entity3 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportJob3 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportJob3?.setData_entity)
                {
                    await
                    ImportJob3.
                    setData_entity(relatedData_entity3);
                }
            
        }
        
    
        
            
            async function associateImportJobWithFile_upload() {
            
                const relatedFile_upload0 = await FileUploads.findOne({
                    offset: Math.floor(Math.random() * (await FileUploads.count())),
                });
                const ImportJob0 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportJob0?.setFile_upload)
                {
                    await
                    ImportJob0.
                    setFile_upload(relatedFile_upload0);
                }
            
                const relatedFile_upload1 = await FileUploads.findOne({
                    offset: Math.floor(Math.random() * (await FileUploads.count())),
                });
                const ImportJob1 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportJob1?.setFile_upload)
                {
                    await
                    ImportJob1.
                    setFile_upload(relatedFile_upload1);
                }
            
                const relatedFile_upload2 = await FileUploads.findOne({
                    offset: Math.floor(Math.random() * (await FileUploads.count())),
                });
                const ImportJob2 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportJob2?.setFile_upload)
                {
                    await
                    ImportJob2.
                    setFile_upload(relatedFile_upload2);
                }
            
                const relatedFile_upload3 = await FileUploads.findOne({
                    offset: Math.floor(Math.random() * (await FileUploads.count())),
                });
                const ImportJob3 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportJob3?.setFile_upload)
                {
                    await
                    ImportJob3.
                    setFile_upload(relatedFile_upload3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateImportJobWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportJob0 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportJob0?.setOrganization)
                {
                    await
                    ImportJob0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportJob1 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportJob1?.setOrganization)
                {
                    await
                    ImportJob1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportJob2 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportJob2?.setOrganization)
                {
                    await
                    ImportJob2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportJob3 = await ImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportJob3?.setOrganization)
                {
                    await
                    ImportJob3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateImportMappingWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportMapping0 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportMapping0?.setTenant)
                {
                    await
                    ImportMapping0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportMapping1 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportMapping1?.setTenant)
                {
                    await
                    ImportMapping1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportMapping2 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportMapping2?.setTenant)
                {
                    await
                    ImportMapping2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportMapping3 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportMapping3?.setTenant)
                {
                    await
                    ImportMapping3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            async function associateImportMappingWithData_entity() {
            
                const relatedData_entity0 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportMapping0 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportMapping0?.setData_entity)
                {
                    await
                    ImportMapping0.
                    setData_entity(relatedData_entity0);
                }
            
                const relatedData_entity1 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportMapping1 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportMapping1?.setData_entity)
                {
                    await
                    ImportMapping1.
                    setData_entity(relatedData_entity1);
                }
            
                const relatedData_entity2 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportMapping2 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportMapping2?.setData_entity)
                {
                    await
                    ImportMapping2.
                    setData_entity(relatedData_entity2);
                }
            
                const relatedData_entity3 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportMapping3 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportMapping3?.setData_entity)
                {
                    await
                    ImportMapping3.
                    setData_entity(relatedData_entity3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateImportMappingWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportMapping0 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportMapping0?.setOrganization)
                {
                    await
                    ImportMapping0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportMapping1 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportMapping1?.setOrganization)
                {
                    await
                    ImportMapping1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportMapping2 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportMapping2?.setOrganization)
                {
                    await
                    ImportMapping2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportMapping3 = await ImportMappings.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportMapping3?.setOrganization)
                {
                    await
                    ImportMapping3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateMappingRuleWithMapping() {
            
                const relatedMapping0 = await ImportMappings.findOne({
                    offset: Math.floor(Math.random() * (await ImportMappings.count())),
                });
                const MappingRule0 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (MappingRule0?.setMapping)
                {
                    await
                    MappingRule0.
                    setMapping(relatedMapping0);
                }
            
                const relatedMapping1 = await ImportMappings.findOne({
                    offset: Math.floor(Math.random() * (await ImportMappings.count())),
                });
                const MappingRule1 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (MappingRule1?.setMapping)
                {
                    await
                    MappingRule1.
                    setMapping(relatedMapping1);
                }
            
                const relatedMapping2 = await ImportMappings.findOne({
                    offset: Math.floor(Math.random() * (await ImportMappings.count())),
                });
                const MappingRule2 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (MappingRule2?.setMapping)
                {
                    await
                    MappingRule2.
                    setMapping(relatedMapping2);
                }
            
                const relatedMapping3 = await ImportMappings.findOne({
                    offset: Math.floor(Math.random() * (await ImportMappings.count())),
                });
                const MappingRule3 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (MappingRule3?.setMapping)
                {
                    await
                    MappingRule3.
                    setMapping(relatedMapping3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateMappingRuleWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const MappingRule0 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (MappingRule0?.setOrganization)
                {
                    await
                    MappingRule0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const MappingRule1 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (MappingRule1?.setOrganization)
                {
                    await
                    MappingRule1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const MappingRule2 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (MappingRule2?.setOrganization)
                {
                    await
                    MappingRule2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const MappingRule3 = await MappingRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (MappingRule3?.setOrganization)
                {
                    await
                    MappingRule3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateValidationRuleSetWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ValidationRuleSet0 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ValidationRuleSet0?.setTenant)
                {
                    await
                    ValidationRuleSet0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ValidationRuleSet1 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ValidationRuleSet1?.setTenant)
                {
                    await
                    ValidationRuleSet1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ValidationRuleSet2 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ValidationRuleSet2?.setTenant)
                {
                    await
                    ValidationRuleSet2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ValidationRuleSet3 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ValidationRuleSet3?.setTenant)
                {
                    await
                    ValidationRuleSet3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            async function associateValidationRuleSetWithData_entity() {
            
                const relatedData_entity0 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ValidationRuleSet0 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ValidationRuleSet0?.setData_entity)
                {
                    await
                    ValidationRuleSet0.
                    setData_entity(relatedData_entity0);
                }
            
                const relatedData_entity1 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ValidationRuleSet1 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ValidationRuleSet1?.setData_entity)
                {
                    await
                    ValidationRuleSet1.
                    setData_entity(relatedData_entity1);
                }
            
                const relatedData_entity2 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ValidationRuleSet2 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ValidationRuleSet2?.setData_entity)
                {
                    await
                    ValidationRuleSet2.
                    setData_entity(relatedData_entity2);
                }
            
                const relatedData_entity3 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ValidationRuleSet3 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ValidationRuleSet3?.setData_entity)
                {
                    await
                    ValidationRuleSet3.
                    setData_entity(relatedData_entity3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateValidationRuleSetWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRuleSet0 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ValidationRuleSet0?.setOrganization)
                {
                    await
                    ValidationRuleSet0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRuleSet1 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ValidationRuleSet1?.setOrganization)
                {
                    await
                    ValidationRuleSet1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRuleSet2 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ValidationRuleSet2?.setOrganization)
                {
                    await
                    ValidationRuleSet2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRuleSet3 = await ValidationRuleSets.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ValidationRuleSet3?.setOrganization)
                {
                    await
                    ValidationRuleSet3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateValidationRuleWithRule_set() {
            
                const relatedRule_set0 = await ValidationRuleSets.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRuleSets.count())),
                });
                const ValidationRule0 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ValidationRule0?.setRule_set)
                {
                    await
                    ValidationRule0.
                    setRule_set(relatedRule_set0);
                }
            
                const relatedRule_set1 = await ValidationRuleSets.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRuleSets.count())),
                });
                const ValidationRule1 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ValidationRule1?.setRule_set)
                {
                    await
                    ValidationRule1.
                    setRule_set(relatedRule_set1);
                }
            
                const relatedRule_set2 = await ValidationRuleSets.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRuleSets.count())),
                });
                const ValidationRule2 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ValidationRule2?.setRule_set)
                {
                    await
                    ValidationRule2.
                    setRule_set(relatedRule_set2);
                }
            
                const relatedRule_set3 = await ValidationRuleSets.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRuleSets.count())),
                });
                const ValidationRule3 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ValidationRule3?.setRule_set)
                {
                    await
                    ValidationRule3.
                    setRule_set(relatedRule_set3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateValidationRuleWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRule0 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ValidationRule0?.setOrganization)
                {
                    await
                    ValidationRule0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRule1 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ValidationRule1?.setOrganization)
                {
                    await
                    ValidationRule1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRule2 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ValidationRule2?.setOrganization)
                {
                    await
                    ValidationRule2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ValidationRule3 = await ValidationRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ValidationRule3?.setOrganization)
                {
                    await
                    ValidationRule3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateImportRowResultWithImport_job() {
            
                const relatedImport_job0 = await ImportJobs.findOne({
                    offset: Math.floor(Math.random() * (await ImportJobs.count())),
                });
                const ImportRowResult0 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportRowResult0?.setImport_job)
                {
                    await
                    ImportRowResult0.
                    setImport_job(relatedImport_job0);
                }
            
                const relatedImport_job1 = await ImportJobs.findOne({
                    offset: Math.floor(Math.random() * (await ImportJobs.count())),
                });
                const ImportRowResult1 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportRowResult1?.setImport_job)
                {
                    await
                    ImportRowResult1.
                    setImport_job(relatedImport_job1);
                }
            
                const relatedImport_job2 = await ImportJobs.findOne({
                    offset: Math.floor(Math.random() * (await ImportJobs.count())),
                });
                const ImportRowResult2 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportRowResult2?.setImport_job)
                {
                    await
                    ImportRowResult2.
                    setImport_job(relatedImport_job2);
                }
            
                const relatedImport_job3 = await ImportJobs.findOne({
                    offset: Math.floor(Math.random() * (await ImportJobs.count())),
                });
                const ImportRowResult3 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportRowResult3?.setImport_job)
                {
                    await
                    ImportRowResult3.
                    setImport_job(relatedImport_job3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateImportRowResultWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportRowResult0 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportRowResult0?.setOrganization)
                {
                    await
                    ImportRowResult0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportRowResult1 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportRowResult1?.setOrganization)
                {
                    await
                    ImportRowResult1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportRowResult2 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportRowResult2?.setOrganization)
                {
                    await
                    ImportRowResult2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportRowResult3 = await ImportRowResults.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportRowResult3?.setOrganization)
                {
                    await
                    ImportRowResult3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateImportIssueWithRow_result() {
            
                const relatedRow_result0 = await ImportRowResults.findOne({
                    offset: Math.floor(Math.random() * (await ImportRowResults.count())),
                });
                const ImportIssue0 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportIssue0?.setRow_result)
                {
                    await
                    ImportIssue0.
                    setRow_result(relatedRow_result0);
                }
            
                const relatedRow_result1 = await ImportRowResults.findOne({
                    offset: Math.floor(Math.random() * (await ImportRowResults.count())),
                });
                const ImportIssue1 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportIssue1?.setRow_result)
                {
                    await
                    ImportIssue1.
                    setRow_result(relatedRow_result1);
                }
            
                const relatedRow_result2 = await ImportRowResults.findOne({
                    offset: Math.floor(Math.random() * (await ImportRowResults.count())),
                });
                const ImportIssue2 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportIssue2?.setRow_result)
                {
                    await
                    ImportIssue2.
                    setRow_result(relatedRow_result2);
                }
            
                const relatedRow_result3 = await ImportRowResults.findOne({
                    offset: Math.floor(Math.random() * (await ImportRowResults.count())),
                });
                const ImportIssue3 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportIssue3?.setRow_result)
                {
                    await
                    ImportIssue3.
                    setRow_result(relatedRow_result3);
                }
            
        }
        
    
        
            
            async function associateImportIssueWithRule() {
            
                const relatedRule0 = await ValidationRules.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRules.count())),
                });
                const ImportIssue0 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportIssue0?.setRule)
                {
                    await
                    ImportIssue0.
                    setRule(relatedRule0);
                }
            
                const relatedRule1 = await ValidationRules.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRules.count())),
                });
                const ImportIssue1 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportIssue1?.setRule)
                {
                    await
                    ImportIssue1.
                    setRule(relatedRule1);
                }
            
                const relatedRule2 = await ValidationRules.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRules.count())),
                });
                const ImportIssue2 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportIssue2?.setRule)
                {
                    await
                    ImportIssue2.
                    setRule(relatedRule2);
                }
            
                const relatedRule3 = await ValidationRules.findOne({
                    offset: Math.floor(Math.random() * (await ValidationRules.count())),
                });
                const ImportIssue3 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportIssue3?.setRule)
                {
                    await
                    ImportIssue3.
                    setRule(relatedRule3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateImportIssueWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportIssue0 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportIssue0?.setOrganization)
                {
                    await
                    ImportIssue0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportIssue1 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportIssue1?.setOrganization)
                {
                    await
                    ImportIssue1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportIssue2 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportIssue2?.setOrganization)
                {
                    await
                    ImportIssue2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportIssue3 = await ImportIssues.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportIssue3?.setOrganization)
                {
                    await
                    ImportIssue3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateImportTemplateWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportTemplate0 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportTemplate0?.setTenant)
                {
                    await
                    ImportTemplate0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportTemplate1 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportTemplate1?.setTenant)
                {
                    await
                    ImportTemplate1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportTemplate2 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportTemplate2?.setTenant)
                {
                    await
                    ImportTemplate2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const ImportTemplate3 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportTemplate3?.setTenant)
                {
                    await
                    ImportTemplate3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            async function associateImportTemplateWithData_entity() {
            
                const relatedData_entity0 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportTemplate0 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportTemplate0?.setData_entity)
                {
                    await
                    ImportTemplate0.
                    setData_entity(relatedData_entity0);
                }
            
                const relatedData_entity1 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportTemplate1 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportTemplate1?.setData_entity)
                {
                    await
                    ImportTemplate1.
                    setData_entity(relatedData_entity1);
                }
            
                const relatedData_entity2 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportTemplate2 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportTemplate2?.setData_entity)
                {
                    await
                    ImportTemplate2.
                    setData_entity(relatedData_entity2);
                }
            
                const relatedData_entity3 = await DataEntities.findOne({
                    offset: Math.floor(Math.random() * (await DataEntities.count())),
                });
                const ImportTemplate3 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportTemplate3?.setData_entity)
                {
                    await
                    ImportTemplate3.
                    setData_entity(relatedData_entity3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateImportTemplateWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportTemplate0 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ImportTemplate0?.setOrganization)
                {
                    await
                    ImportTemplate0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportTemplate1 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ImportTemplate1?.setOrganization)
                {
                    await
                    ImportTemplate1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportTemplate2 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ImportTemplate2?.setOrganization)
                {
                    await
                    ImportTemplate2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const ImportTemplate3 = await ImportTemplates.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ImportTemplate3?.setOrganization)
                {
                    await
                    ImportTemplate3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateProductWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Product0 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Product0?.setTenant)
                {
                    await
                    Product0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Product1 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Product1?.setTenant)
                {
                    await
                    Product1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Product2 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Product2?.setTenant)
                {
                    await
                    Product2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Product3 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Product3?.setTenant)
                {
                    await
                    Product3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateProductWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Product0 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Product0?.setOrganization)
                {
                    await
                    Product0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Product1 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Product1?.setOrganization)
                {
                    await
                    Product1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Product2 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Product2?.setOrganization)
                {
                    await
                    Product2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Product3 = await Products.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Product3?.setOrganization)
                {
                    await
                    Product3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateCustomerWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Customer0 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Customer0?.setTenant)
                {
                    await
                    Customer0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Customer1 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Customer1?.setTenant)
                {
                    await
                    Customer1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Customer2 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Customer2?.setTenant)
                {
                    await
                    Customer2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Customer3 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Customer3?.setTenant)
                {
                    await
                    Customer3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateCustomerWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Customer0 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Customer0?.setOrganization)
                {
                    await
                    Customer0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Customer1 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Customer1?.setOrganization)
                {
                    await
                    Customer1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Customer2 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Customer2?.setOrganization)
                {
                    await
                    Customer2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Customer3 = await Customers.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Customer3?.setOrganization)
                {
                    await
                    Customer3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateSupplierWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Supplier0 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Supplier0?.setTenant)
                {
                    await
                    Supplier0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Supplier1 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Supplier1?.setTenant)
                {
                    await
                    Supplier1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Supplier2 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Supplier2?.setTenant)
                {
                    await
                    Supplier2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const Supplier3 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Supplier3?.setTenant)
                {
                    await
                    Supplier3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateSupplierWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Supplier0 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Supplier0?.setOrganization)
                {
                    await
                    Supplier0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Supplier1 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Supplier1?.setOrganization)
                {
                    await
                    Supplier1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Supplier2 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Supplier2?.setOrganization)
                {
                    await
                    Supplier2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const Supplier3 = await Suppliers.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Supplier3?.setOrganization)
                {
                    await
                    Supplier3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateAvailabilityRecordWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AvailabilityRecord0 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (AvailabilityRecord0?.setTenant)
                {
                    await
                    AvailabilityRecord0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AvailabilityRecord1 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (AvailabilityRecord1?.setTenant)
                {
                    await
                    AvailabilityRecord1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AvailabilityRecord2 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (AvailabilityRecord2?.setTenant)
                {
                    await
                    AvailabilityRecord2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AvailabilityRecord3 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (AvailabilityRecord3?.setTenant)
                {
                    await
                    AvailabilityRecord3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateAvailabilityRecordWithOrganization() {
            
                const relatedOrganization0 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const AvailabilityRecord0 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (AvailabilityRecord0?.setOrganization)
                {
                    await
                    AvailabilityRecord0.
                    setOrganization(relatedOrganization0);
                }
            
                const relatedOrganization1 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const AvailabilityRecord1 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (AvailabilityRecord1?.setOrganization)
                {
                    await
                    AvailabilityRecord1.
                    setOrganization(relatedOrganization1);
                }
            
                const relatedOrganization2 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const AvailabilityRecord2 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (AvailabilityRecord2?.setOrganization)
                {
                    await
                    AvailabilityRecord2.
                    setOrganization(relatedOrganization2);
                }
            
                const relatedOrganization3 = await Organizations.findOne({
                    offset: Math.floor(Math.random() * (await Organizations.count())),
                });
                const AvailabilityRecord3 = await AvailabilityRecords.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (AvailabilityRecord3?.setOrganization)
                {
                    await
                    AvailabilityRecord3.
                    setOrganization(relatedOrganization3);
                }
            
        }
        
    

    
    
    
        
            
            async function associateAuditEventWithTenant() {
            
                const relatedTenant0 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AuditEvent0 = await AuditEvents.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (AuditEvent0?.setTenant)
                {
                    await
                    AuditEvent0.
                    setTenant(relatedTenant0);
                }
            
                const relatedTenant1 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AuditEvent1 = await AuditEvents.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (AuditEvent1?.setTenant)
                {
                    await
                    AuditEvent1.
                    setTenant(relatedTenant1);
                }
            
                const relatedTenant2 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AuditEvent2 = await AuditEvents.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (AuditEvent2?.setTenant)
                {
                    await
                    AuditEvent2.
                    setTenant(relatedTenant2);
                }
            
                const relatedTenant3 = await Tenants.findOne({
                    offset: Math.floor(Math.random() * (await Tenants.count())),
                });
                const AuditEvent3 = await AuditEvents.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (AuditEvent3?.setTenant)
                {
                    await
                    AuditEvent3.
                    setTenant(relatedTenant3);
                }
            
        }
        
    
        
            
            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);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            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);
                }
            
        }
        
    


module.exports = {
    up: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
                
                await Organizations.bulkCreate(OrganizationsData);
                
            
            
                
                await Tenants.bulkCreate(TenantsData);
                
            
            
                
                await DataEntities.bulkCreate(DataEntitiesData);
                
            
            
                
                await ImportSources.bulkCreate(ImportSourcesData);
                
            
            
                
                await FileUploads.bulkCreate(FileUploadsData);
                
            
            
                
                await ImportJobs.bulkCreate(ImportJobsData);
                
            
            
                
                await ImportMappings.bulkCreate(ImportMappingsData);
                
            
            
                
                await MappingRules.bulkCreate(MappingRulesData);
                
            
            
                
                await ValidationRuleSets.bulkCreate(ValidationRuleSetsData);
                
            
            
                
                await ValidationRules.bulkCreate(ValidationRulesData);
                
            
            
                
                await ImportRowResults.bulkCreate(ImportRowResultsData);
                
            
            
                
                await ImportIssues.bulkCreate(ImportIssuesData);
                
            
            
                
                await ImportTemplates.bulkCreate(ImportTemplatesData);
                
            
            
                
                await Products.bulkCreate(ProductsData);
                
            
            
                
                await Customers.bulkCreate(CustomersData);
                
            
            
                
                await Suppliers.bulkCreate(SuppliersData);
                
            
            
                
                await AvailabilityRecords.bulkCreate(AvailabilityRecordsData);
                
            
            
                
                await AuditEvents.bulkCreate(AuditEventsData);
                
            
            await Promise.all([
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
                    
                        
                        await associateUserWithOrganization(),
                    
                
            
                
                
                
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateTenantWithOrganization(),
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateDataEntityWithTenant(),
                    
                
                    
                        
                        await associateDataEntityWithOrganization(),
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateImportSourceWithTenant(),
                    
                
                    
                        
                        await associateImportSourceWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateFileUploadWithTenant(),
                    
                
                    
                        
                        await associateFileUploadWithUploaded_by(),
                    
                
                    
                        
                        await associateFileUploadWithSource(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateFileUploadWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateImportJobWithTenant(),
                    
                
                    
                        
                        await associateImportJobWithRequested_by(),
                    
                
                    
                        
                        await associateImportJobWithData_entity(),
                    
                
                    
                        
                        await associateImportJobWithFile_upload(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateImportJobWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateImportMappingWithTenant(),
                    
                
                    
                        
                        await associateImportMappingWithData_entity(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateImportMappingWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateMappingRuleWithMapping(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateMappingRuleWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateValidationRuleSetWithTenant(),
                    
                
                    
                        
                        await associateValidationRuleSetWithData_entity(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateValidationRuleSetWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateValidationRuleWithRule_set(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateValidationRuleWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateImportRowResultWithImport_job(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateImportRowResultWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateImportIssueWithRow_result(),
                    
                
                    
                        
                        await associateImportIssueWithRule(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateImportIssueWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateImportTemplateWithTenant(),
                    
                
                    
                        
                        await associateImportTemplateWithData_entity(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateImportTemplateWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateProductWithTenant(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateProductWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateCustomerWithTenant(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateCustomerWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateSupplierWithTenant(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateSupplierWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateAvailabilityRecordWithTenant(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateAvailabilityRecordWithOrganization(),
                    
                
            
                
                
                    
                        
                        await associateAuditEventWithTenant(),
                    
                
                    
                        
                        await associateAuditEventWithActor(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateAuditEventWithOrganization(),
                    
                
            
            ]);
        
    },

    down: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
            await queryInterface.bulkDelete('organizations', null, {});
            
            
            await queryInterface.bulkDelete('tenants', null, {});
            
            
            await queryInterface.bulkDelete('data_entities', null, {});
            
            
            await queryInterface.bulkDelete('import_sources', null, {});
            
            
            await queryInterface.bulkDelete('file_uploads', null, {});
            
            
            await queryInterface.bulkDelete('import_jobs', null, {});
            
            
            await queryInterface.bulkDelete('import_mappings', null, {});
            
            
            await queryInterface.bulkDelete('mapping_rules', null, {});
            
            
            await queryInterface.bulkDelete('validation_rule_sets', null, {});
            
            
            await queryInterface.bulkDelete('validation_rules', null, {});
            
            
            await queryInterface.bulkDelete('import_row_results', null, {});
            
            
            await queryInterface.bulkDelete('import_issues', null, {});
            
            
            await queryInterface.bulkDelete('import_templates', null, {});
            
            
            await queryInterface.bulkDelete('products', null, {});
            
            
            await queryInterface.bulkDelete('customers', null, {});
            
            
            await queryInterface.bulkDelete('suppliers', null, {});
            
            
            await queryInterface.bulkDelete('availability_records', null, {});
            
            
            await queryInterface.bulkDelete('audit_events', null, {});
            
        
    },
};