





















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






const BillingCustomers = db.billing_customers;

const Subscriptions = db.subscriptions;

const TradingAccounts = db.trading_accounts;

const Instruments = db.instruments;

const Setups = db.setups;

const Tags = db.tags;

const Trades = db.trades;

const TradeAttachments = db.trade_attachments;

const TradeRules = db.trade_rules;

const TradeRuleChecks = db.trade_rule_checks;

const MoodEntries = db.mood_entries;

const Goals = db.goals;

const Milestones = db.milestones;

const WatchlistItems = db.watchlist_items;

const EconomicEvents = db.economic_events;

const CsvImportJobs = db.csv_import_jobs;

const CsvImportRowErrors = db.csv_import_row_errors;

const BrokerConnections = db.broker_connections;

const TradeSyncRuns = db.trade_sync_runs;

const AiInsightRuns = db.ai_insight_runs;

const AiInsightItems = db.ai_insight_items;

const AlertRules = db.alert_rules;

const Alerts = db.alerts;

const DashboardWidgets = db.dashboard_widgets;

const PdfReports = db.pdf_reports;







const BillingCustomersData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "provider": "stripe",
            
        
    
        
        
            
                "provider_customer_ref": "cus_PJ_001",
            
        
    
        
        
            
                "default_currency": "USD",
            
        
    
        
        
            
                "linked_at": new Date('2026-01-01T00:01:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "provider": "stripe",
            
        
    
        
        
            
                "provider_customer_ref": "cus_PJ_002",
            
        
    
        
        
            
                "default_currency": "USD",
            
        
    
        
        
            
                "linked_at": new Date('2026-01-15T00:01:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "provider": "stripe",
            
        
    
        
        
            
                "provider_customer_ref": "cus_PJ_003",
            
        
    
        
        
            
                "default_currency": "GBP",
            
        
    
        
        
            
                "linked_at": new Date('2026-02-01T00:01:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const SubscriptionsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "provider": "stripe",
            
        
    
        
        
            
                "provider_subscription_ref": "sub_PJ_001",
            
        
    
        
        
            
                "tier": "free",
            
        
    
        
        
            
                "status": "unpaid",
            
        
    
        
        
            
                "current_period_start_at": new Date('2026-02-01T00:00:00Z'),
            
        
    
        
        
            
                "current_period_end_at": new Date('2026-03-01T00:00:00Z'),
            
        
    
        
        
            
                "cancel_at_period_end": true,
            
        
    
        
        
            
                "canceled_at": new Date('2025-12-31T00:00:00Z'),
            
        
    
        
        
            
                "price_ref": "price_premium_10",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "provider": "stripe",
            
        
    
        
        
            
                "provider_subscription_ref": "sub_PJ_002",
            
        
    
        
        
            
                "tier": "starter",
            
        
    
        
        
            
                "status": "incomplete",
            
        
    
        
        
            
                "current_period_start_at": new Date('2026-01-15T00:00:00Z'),
            
        
    
        
        
            
                "current_period_end_at": new Date('2026-02-15T00:00:00Z'),
            
        
    
        
        
            
                "cancel_at_period_end": false,
            
        
    
        
        
            
                "canceled_at": new Date('2025-12-31T00:00:00Z'),
            
        
    
        
        
            
                "price_ref": "price_starter_1",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "provider": "stripe",
            
        
    
        
        
            
                "provider_subscription_ref": "sub_PJ_003",
            
        
    
        
        
            
                "tier": "premium",
            
        
    
        
        
            
                "status": "incomplete",
            
        
    
        
        
            
                "current_period_start_at": new Date('2026-02-01T00:00:00Z'),
            
        
    
        
        
            
                "current_period_end_at": new Date('2026-03-01T00:00:00Z'),
            
        
    
        
        
            
                "cancel_at_period_end": true,
            
        
    
        
        
            
                "canceled_at": new Date('2025-12-31T00:00:00Z'),
            
        
    
        
        
            
                "price_ref": "price_free_0",
            
        
    
    },
    
];



const TradingAccountsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "OC Futures Main",
            
        
    
        
        
            
                "broker_name": "Interactive Brokers",
            
        
    
        
        
            
                "base_currency": "USD",
            
        
    
        
        
            
                "starting_balance": 50000.0,
            
        
    
        
        
            
                "current_balance": 56420.75,
            
        
    
        
        
            
                "risk_per_trade_default": 0.5,
            
        
    
        
        
            
                "risk_unit": "currency",
            
        
    
        
        
            
                "is_archived": false,
            
        
    
        
        
            
                "opened_at": new Date('2025-11-01T00:00:00Z'),
            
        
    
        
        
            
                "archived_at": new Date('2025-12-31T00:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "OC Crypto Swing",
            
        
    
        
        
            
                "broker_name": "Binance",
            
        
    
        
        
            
                "base_currency": "USD",
            
        
    
        
        
            
                "starting_balance": 15000.0,
            
        
    
        
        
            
                "current_balance": 17210.3,
            
        
    
        
        
            
                "risk_per_trade_default": 1.0,
            
        
    
        
        
            
                "risk_unit": "percent",
            
        
    
        
        
            
                "is_archived": true,
            
        
    
        
        
            
                "opened_at": new Date('2025-12-05T00:00:00Z'),
            
        
    
        
        
            
                "archived_at": new Date('2025-12-31T00:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "MR Options",
            
        
    
        
        
            
                "broker_name": "Tastytrade",
            
        
    
        
        
            
                "base_currency": "USD",
            
        
    
        
        
            
                "starting_balance": 20000.0,
            
        
    
        
        
            
                "current_balance": 19860.12,
            
        
    
        
        
            
                "risk_per_trade_default": 150.0,
            
        
    
        
        
            
                "risk_unit": "currency",
            
        
    
        
        
            
                "is_archived": false,
            
        
    
        
        
            
                "opened_at": new Date('2025-10-10T00:00:00Z'),
            
        
    
        
        
            
                "archived_at": new Date('2025-12-31T00:00:00Z'),
            
        
    
    },
    
];



const InstrumentsData = [
    
    {
    
        
        
            
                "symbol": "ES",
            
        
    
        
        
            
                "name": "E-mini S&P 500",
            
        
    
        
        
            
                "asset_class": "stocks",
            
        
    
        
        
            
                "exchange": "CME",
            
        
    
        
        
            
                "tick_size": "0.25",
            
        
    
        
        
            
                "pip_value_hint": "12.50 per point",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "symbol": "NQ",
            
        
    
        
        
            
                "name": "E-mini Nasdaq 100",
            
        
    
        
        
            
                "asset_class": "crypto",
            
        
    
        
        
            
                "exchange": "CME",
            
        
    
        
        
            
                "tick_size": "0.25",
            
        
    
        
        
            
                "pip_value_hint": "5.00 per point",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "symbol": "EURUSD",
            
        
    
        
        
            
                "name": "Euro vs US Dollar",
            
        
    
        
        
            
                "asset_class": "bonds",
            
        
    
        
        
            
                "exchange": "OTC",
            
        
    
        
        
            
                "tick_size": "0.00001",
            
        
    
        
        
            
                "pip_value_hint": "10 per pip per standard lot",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const SetupsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "NY Open Breakout",
            
        
    
        
        
            
                "description": "Breakout after initial range with volume confirmation.",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Pullback To VWAP",
            
        
    
        
        
            
                "description": "Trend day pullback entry at VWAP with tight stop.",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Earnings Volatility Crush",
            
        
    
        
        
            
                "description": "Short premium after earnings with defined risk spreads.",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const TagsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "A+ Setup",
            
        
    
        
        
            
                "color_hex": "#0ea5e9",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Overconfident",
            
        
    
        
        
            
                "color_hex": "#f59e0b",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Hedge",
            
        
    
        
        
            
                "color_hex": "#3b82f6",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const TradesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "direction": "short",
            
        
    
        
        
            
                "status": "closed",
            
        
    
        
        
            
                "timeframe": "1d",
            
        
    
        
        
            
                "entry_at": new Date('2026-02-03T14:35:00Z'),
            
        
    
        
        
            
                "exit_at": new Date('2026-02-03T15:10:00Z'),
            
        
    
        
        
            
                "entry_price": 4948.25,
            
        
    
        
        
            
                "exit_price": 4961.75,
            
        
    
        
        
            
                "stop_loss_price": 4942.25,
            
        
    
        
        
            
                "take_profit_price": 4962.25,
            
        
    
        
        
            
                "position_size": 2.0,
            
        
    
        
        
            
                "position_size_unit": "shares",
            
        
    
        
        
            
                "fees": 4.68,
            
        
    
        
        
            
                "slippage": 1.0,
            
        
    
        
        
            
                "pnl_amount": 529.32,
            
        
    
        
        
            
                "pnl_percent": 1.06,
            
        
    
        
        
            
                "risk_amount": 240.0,
            
        
    
        
        
            
                "rr_ratio": 2.2,
            
        
    
        
        
            
                "mae_amount": -85.0,
            
        
    
        
        
            
                "mfe_amount": 610.0,
            
        
    
        
        
            
                "duration_minutes": 35.0,
            
        
    
        
        
            
                "is_win": true,
            
        
    
        
        
            
                "notes": "Clean range break after opening sweep. Followed plan and managed stop.",
            
        
    
        
        
            
                // type code here for "relation_many" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "direction": "short",
            
        
    
        
        
            
                "status": "open",
            
        
    
        
        
            
                "timeframe": "1m",
            
        
    
        
        
            
                "entry_at": new Date('2026-02-01T10:00:00Z'),
            
        
    
        
        
            
                "exit_at": new Date('2026-02-02T08:00:00Z'),
            
        
    
        
        
            
                "entry_price": 42750.0,
            
        
    
        
        
            
                "exit_price": 43920.0,
            
        
    
        
        
            
                "stop_loss_price": 41980.0,
            
        
    
        
        
            
                "take_profit_price": 44200.0,
            
        
    
        
        
            
                "position_size": 0.35,
            
        
    
        
        
            
                "position_size_unit": "contracts",
            
        
    
        
        
            
                "fees": 12.5,
            
        
    
        
        
            
                "slippage": 0.0,
            
        
    
        
        
            
                "pnl_amount": 396.25,
            
        
    
        
        
            
                "pnl_percent": 2.64,
            
        
    
        
        
            
                "risk_amount": 269.5,
            
        
    
        
        
            
                "rr_ratio": 1.47,
            
        
    
        
        
            
                "mae_amount": -210.0,
            
        
    
        
        
            
                "mfe_amount": 470.0,
            
        
    
        
        
            
                "duration_minutes": 1320.0,
            
        
    
        
        
            
                "is_win": true,
            
        
    
        
        
            
                "notes": "Good patience on pullback. Could have scaled out earlier into resistance.",
            
        
    
        
        
            
                // type code here for "relation_many" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "direction": "long",
            
        
    
        
        
            
                "status": "open",
            
        
    
        
        
            
                "timeframe": "5m",
            
        
    
        
        
            
                "entry_at": new Date('2026-02-05T15:40:00Z'),
            
        
    
        
        
            
                "exit_at": new Date('2026-02-06T15:35:00Z'),
            
        
    
        
        
            
                "entry_price": 189.5,
            
        
    
        
        
            
                "exit_price": 187.9,
            
        
    
        
        
            
                "stop_loss_price": 192.0,
            
        
    
        
        
            
                "take_profit_price": 186.5,
            
        
    
        
        
            
                "position_size": 5.0,
            
        
    
        
        
            
                "position_size_unit": "contracts",
            
        
    
        
        
            
                "fees": 7.25,
            
        
    
        
        
            
                "slippage": 0.2,
            
        
    
        
        
            
                "pnl_amount": 215.0,
            
        
    
        
        
            
                "pnl_percent": 1.08,
            
        
    
        
        
            
                "risk_amount": 250.0,
            
        
    
        
        
            
                "rr_ratio": 0.86,
            
        
    
        
        
            
                "mae_amount": -120.0,
            
        
    
        
        
            
                "mfe_amount": 260.0,
            
        
    
        
        
            
                "duration_minutes": 1435.0,
            
        
    
        
        
            
                "is_win": true,
            
        
    
        
        
            
                "notes": "Defined risk spread held through IV collapse. Execution was solid.",
            
        
    
        
        
            
                // type code here for "relation_many" field
            
        
    
    },
    
];



const TradeAttachmentsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "attachment_type": "other",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "caption": "ES breakout chart",
            
        
    
        
        
            
                "captured_at": new Date('2026-02-03T15:12:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "attachment_type": "chart",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "caption": "BTC 4H VWAP pullback",
            
        
    
        
        
            
                "captured_at": new Date('2026-02-02T08:05:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "attachment_type": "other",
            
        
    
        
        
            
                // type code here for "images" field
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "caption": "AAPL spread fills",
            
        
    
        
        
            
                "captured_at": new Date('2026-02-06T15:40:00Z'),
            
        
    
    },
    
];



const TradeRulesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Stop set before entry",
            
        
    
        
        
            
                "description": "Always define stop loss before entering the trade.",
            
        
    
        
        
            
                "severity": "medium",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Max 3 trades per session",
            
        
    
        
        
            
                "description": "Avoid overtrading by limiting number of discretionary entries.",
            
        
    
        
        
            
                "severity": "low",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Defined risk only",
            
        
    
        
        
            
                "description": "Use spreads or hedges; no naked short options.",
            
        
    
        
        
            
                "severity": "high",
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const TradeRuleChecksData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "result": "not_applicable",
            
        
    
        
        
            
                "score": 1.0,
            
        
    
        
        
            
                "comment": "Stop and target defined prior to entry.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "result": "pass",
            
        
    
        
        
            
                "score": 1.0,
            
        
    
        
        
            
                "comment": "Stop was set and respected.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "result": "not_applicable",
            
        
    
        
        
            
                "score": 1.0,
            
        
    
        
        
            
                "comment": "Trade was a defined-risk spread.",
            
        
    
    },
    
];



const MoodEntriesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "mood": "euphoric",
            
        
    
        
        
            
                "confidence_level": "medium",
            
        
    
        
        
            
                "discipline_level": "very_high",
            
        
    
        
        
            
                "stress_score": 2.0,
            
        
    
        
        
            
                "emotions_notes": "Calm and patient. Followed process and avoided chasing.",
            
        
    
        
        
            
                "recorded_at": new Date('2026-02-03T15:15:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "mood": "neutral",
            
        
    
        
        
            
                "confidence_level": "high",
            
        
    
        
        
            
                "discipline_level": "medium",
            
        
    
        
        
            
                "stress_score": 3.0,
            
        
    
        
        
            
                "emotions_notes": "Comfortable holding but watched resistance levels closely.",
            
        
    
        
        
            
                "recorded_at": new Date('2026-02-02T08:10:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "mood": "calm",
            
        
    
        
        
            
                "confidence_level": "very_high",
            
        
    
        
        
            
                "discipline_level": "high",
            
        
    
        
        
            
                "stress_score": 2.5,
            
        
    
        
        
            
                "emotions_notes": "Stuck to plan; no urge to overmanage.",
            
        
    
        
        
            
                "recorded_at": new Date('2026-02-06T15:45:00Z'),
            
        
    
    },
    
];



const GoalsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "Keep monthly drawdown under 3%",
            
        
    
        
        
            
                "description": "Prioritize consistency and avoid large losing days.",
            
        
    
        
        
            
                "goal_type": "custom",
            
        
    
        
        
            
                "target_value": 3.0,
            
        
    
        
        
            
                "current_value": 1.2,
            
        
    
        
        
            
                "period": "weekly",
            
        
    
        
        
            
                "start_at": new Date('2026-02-01T00:00:00Z'),
            
        
    
        
        
            
                "end_at": new Date('2026-03-01T23:59:00Z'),
            
        
    
        
        
            
                "status": "paused",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "Achieve 1.5 profit factor",
            
        
    
        
        
            
                "description": "Improve selection and reduce low-quality entries.",
            
        
    
        
        
            
                "goal_type": "max_drawdown",
            
        
    
        
        
            
                "target_value": 1.5,
            
        
    
        
        
            
                "current_value": 1.3,
            
        
    
        
        
            
                "period": "quarterly",
            
        
    
        
        
            
                "start_at": new Date('2026-02-01T00:00:00Z'),
            
        
    
        
        
            
                "end_at": new Date('2026-03-01T23:59:00Z'),
            
        
    
        
        
            
                "status": "failed",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "Limit risk per trade to 250",
            
        
    
        
        
            
                "description": "Keep defined risk sizing consistent across spreads.",
            
        
    
        
        
            
                "goal_type": "sharpe_ratio",
            
        
    
        
        
            
                "target_value": 250.0,
            
        
    
        
        
            
                "current_value": 250.0,
            
        
    
        
        
            
                "period": "monthly",
            
        
    
        
        
            
                "start_at": new Date('2026-02-01T00:00:00Z'),
            
        
    
        
        
            
                "end_at": new Date('2026-03-01T23:59:00Z'),
            
        
    
        
        
            
                "status": "failed",
            
        
    
    },
    
];



const MilestonesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "No red day over 1%",
            
        
    
        
        
            
                "notes": "Cut losers quickly; stop for day if threshold hit.",
            
        
    
        
        
            
                "target_value": 1.0,
            
        
    
        
        
            
                "due_at": new Date('2026-02-15T23:59:00Z'),
            
        
    
        
        
            
                "achieved_at": new Date('2026-02-15T16:30:00Z'),
            
        
    
        
        
            
                "status": "pending",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "Remove lowest quality setup",
            
        
    
        
        
            
                "notes": "Stop taking marginal pullbacks without confluence.",
            
        
    
        
        
            
                "target_value": 1.0,
            
        
    
        
        
            
                "due_at": new Date('2026-02-10T23:59:00Z'),
            
        
    
        
        
            
                "achieved_at": new Date('2026-02-09T12:00:00Z'),
            
        
    
        
        
            
                "status": "missed",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "Audit sizing weekly",
            
        
    
        
        
            
                "notes": "Verify max loss for each spread before entry.",
            
        
    
        
        
            
                "target_value": 1.0,
            
        
    
        
        
            
                "due_at": new Date('2026-02-07T23:59:00Z'),
            
        
    
        
        
            
                "achieved_at": new Date('2026-02-07T18:00:00Z'),
            
        
    
        
        
            
                "status": "missed",
            
        
    
    },
    
];



const WatchlistItemsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "thesis": "Watching for a trend day; key level near prior session high.",
            
        
    
        
        
            
                "priority": "medium",
            
        
    
        
        
            
                "next_review_at": new Date('2026-02-07T13:00:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "thesis": "Support at weekly VWAP area; wait for reaction and volume.",
            
        
    
        
        
            
                "priority": "high",
            
        
    
        
        
            
                "next_review_at": new Date('2026-02-07T13:00:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "thesis": "Post-earnings drift; consider defined risk premium selling if IV remains elevated.",
            
        
    
        
        
            
                "priority": "medium",
            
        
    
        
        
            
                "next_review_at": new Date('2026-02-08T14:00:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
];



const EconomicEventsData = [
    
    {
    
        
        
            
                "title": "US Nonfarm Payrolls",
            
        
    
        
        
            
                "country": "United States",
            
        
    
        
        
            
                "impact": "medium",
            
        
    
        
        
            
                "currency": "USD",
            
        
    
        
        
            
                "event_at": new Date('2026-02-06T13:30:00Z'),
            
        
    
        
        
            
                "source": "InvestingCalendar",
            
        
    
        
        
            
                "external_ref": "EVT_US_NFP_2026_02",
            
        
    
        
        
            
                "description": "Monthly employment report; often drives volatility across indices and FX.",
            
        
    
    },
    
    {
    
        
        
            
                "title": "FOMC Meeting Minutes",
            
        
    
        
        
            
                "country": "United States",
            
        
    
        
        
            
                "impact": "low",
            
        
    
        
        
            
                "currency": "USD",
            
        
    
        
        
            
                "event_at": new Date('2026-02-05T19:00:00Z'),
            
        
    
        
        
            
                "source": "InvestingCalendar",
            
        
    
        
        
            
                "external_ref": "EVT_US_FOMC_MIN_2026_02",
            
        
    
        
        
            
                "description": "Federal Reserve minutes release; can move rates and USD.",
            
        
    
    },
    
    {
    
        
        
            
                "title": "ECB Rate Decision",
            
        
    
        
        
            
                "country": "Eurozone",
            
        
    
        
        
            
                "impact": "high",
            
        
    
        
        
            
                "currency": "EUR",
            
        
    
        
        
            
                "event_at": new Date('2026-02-04T12:45:00Z'),
            
        
    
        
        
            
                "source": "InvestingCalendar",
            
        
    
        
        
            
                "external_ref": "EVT_EU_ECB_2026_02",
            
        
    
        
        
            
                "description": "European Central Bank rate decision and statement.",
            
        
    
    },
    
];



const CsvImportJobsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "queued",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "original_filename": "oc_futures_jan.csv",
            
        
    
        
        
            
                "mapping_json": "{instrument:Symbol,entry_at:EntryTime,exit_at:ExitTime,entry_price:EntryPrice,exit_price:ExitPrice,position_size:Qty,direction:Side}",
            
        
    
        
        
            
                "total_rows": 120,
            
        
    
        
        
            
                "imported_rows": 118,
            
        
    
        
        
            
                "failed_rows": 2,
            
        
    
        
        
            
                "error_summary": "2 rows failed due to missing ExitTime.",
            
        
    
        
        
            
                "started_at": new Date('2026-02-01T02:10:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2026-02-01T02:12:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "processing",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "original_filename": "oc_crypto_q1.csv",
            
        
    
        
        
            
                "mapping_json": "{instrument:Market,entry_at:OpenTime,exit_at:CloseTime,entry_price:Open,exit_price:Close,position_size:Size,direction:Direction}",
            
        
    
        
        
            
                "total_rows": 42,
            
        
    
        
        
            
                "imported_rows": 42,
            
        
    
        
        
            
                "failed_rows": 0,
            
        
    
        
        
            
                "error_summary": "No errors.",
            
        
    
        
        
            
                "started_at": new Date('2026-02-02T03:05:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2026-02-02T03:06:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "canceled",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "original_filename": "mr_options_fills.csv",
            
        
    
        
        
            
                "mapping_json": "{instrument:Underlying,entry_at:OpenTime,exit_at:CloseTime,fees:Fees}",
            
        
    
        
        
            
                "total_rows": 65,
            
        
    
        
        
            
                "imported_rows": 0,
            
        
    
        
        
            
                "failed_rows": 65,
            
        
    
        
        
            
                "error_summary": "Mapping missing required fields for position size and direction.",
            
        
    
        
        
            
                "started_at": new Date('2026-02-03T01:20:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2026-02-03T01:21:00Z'),
            
        
    
    },
    
];



const CsvImportRowErrorsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "row_number": 44,
            
        
    
        
        
            
                "raw_row_json": "{Symbol:ES,EntryTime:2026-01-11 14:31,ExitTime:,EntryPrice:4788.25,ExitPrice:4790.25,Qty:1,Side:Buy}",
            
        
    
        
        
            
                "error_message": "ExitTime is required for closed trades.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "row_number": 97,
            
        
    
        
        
            
                "raw_row_json": "{Symbol:NQ,EntryTime:2026-01-27 15:05,ExitTime:,EntryPrice:16892.5,ExitPrice:16870.0,Qty:1,Side:Sell}",
            
        
    
        
        
            
                "error_message": "ExitTime is required for closed trades.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "row_number": 3,
            
        
    
        
        
            
                "raw_row_json": "{Underlying:AAPL,OpenTime:2026-01-22 15:40,CloseTime:2026-01-23 15:35,Fees:1.25}",
            
        
    
        
        
            
                "error_message": "Missing required mapping for direction and position size.",
            
        
    
    },
    
];



const BrokerConnectionsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "broker": "kraken",
            
        
    
        
        
            
                "status": "pending",
            
        
    
        
        
            
                "connection_label": "IBKR Main",
            
        
    
        
        
            
                "sync_enabled": true,
            
        
    
        
        
            
                "last_sync_at": new Date('2026-02-06T18:30:00Z'),
            
        
    
        
        
            
                "last_error": "No issues.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "broker": "binance",
            
        
    
        
        
            
                "status": "pending",
            
        
    
        
        
            
                "connection_label": "Binance Spot",
            
        
    
        
        
            
                "sync_enabled": true,
            
        
    
        
        
            
                "last_sync_at": new Date('2026-02-06T18:10:00Z'),
            
        
    
        
        
            
                "last_error": "No issues.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "broker": "metatrader4",
            
        
    
        
        
            
                "status": "disconnected",
            
        
    
        
        
            
                "connection_label": "Broker CSV Bridge",
            
        
    
        
        
            
                "sync_enabled": false,
            
        
    
        
        
            
                "last_sync_at": new Date('2026-02-03T01:21:00Z'),
            
        
    
        
        
            
                "last_error": "Token expired; reconnect required.",
            
        
    
    },
    
];



const TradeSyncRunsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "failed",
            
        
    
        
        
            
                "started_at": new Date('2026-02-06T18:00:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2026-02-06T18:01:10Z'),
            
        
    
        
        
            
                "created_trades": 12,
            
        
    
        
        
            
                "updated_trades": 4,
            
        
    
        
        
            
                "skipped_trades": 3,
            
        
    
        
        
            
                "error_details": "No errors.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "completed",
            
        
    
        
        
            
                "started_at": new Date('2026-02-06T18:05:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2026-02-06T18:05:45Z'),
            
        
    
        
        
            
                "created_trades": 6,
            
        
    
        
        
            
                "updated_trades": 0,
            
        
    
        
        
            
                "skipped_trades": 1,
            
        
    
        
        
            
                "error_details": "No errors.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "started",
            
        
    
        
        
            
                "started_at": new Date('2026-02-03T01:20:00Z'),
            
        
    
        
        
            
                "finished_at": new Date('2026-02-03T01:21:00Z'),
            
        
    
        
        
            
                "created_trades": 0,
            
        
    
        
        
            
                "updated_trades": 0,
            
        
    
        
        
            
                "skipped_trades": 0,
            
        
    
        
        
            
                "error_details": "Authentication failed during sync.",
            
        
    
    },
    
];



const AiInsightRunsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "run_type": "trade_review",
            
        
    
        
        
            
                "status": "failed",
            
        
    
        
        
            
                "period_start_at": new Date('2026-02-03T00:00:00Z'),
            
        
    
        
        
            
                "period_end_at": new Date('2026-02-03T23:59:59Z'),
            
        
    
        
        
            
                "prompt_snapshot": "Summarize performance and behavior for the day using trades and rule checks.",
            
        
    
        
        
            
                "output_summary": "Strong discipline with one high-quality breakout trade. Risk was controlled and execution aligned with plan.",
            
        
    
        
        
            
                "consistency_score": 8.6,
            
        
    
        
        
            
                "completed_at": new Date('2026-02-04T00:02:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "run_type": "daily_summary",
            
        
    
        
        
            
                "status": "failed",
            
        
    
        
        
            
                "period_start_at": new Date('2026-01-01T00:00:00Z'),
            
        
    
        
        
            
                "period_end_at": new Date('2026-02-06T23:59:59Z'),
            
        
    
        
        
            
                "prompt_snapshot": "Detect recurring patterns in winners and losers across crypto swing trades.",
            
        
    
        
        
            
                "output_summary": "Best outcomes occur when entries align with higher timeframe trend and VWAP confluence. Avoid trades into nearby resistance.",
            
        
    
        
        
            
                "consistency_score": 7.9,
            
        
    
        
        
            
                "completed_at": new Date('2026-02-06T12:05:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "run_type": "market_condition",
            
        
    
        
        
            
                "status": "completed",
            
        
    
        
        
            
                "period_start_at": new Date('2026-02-01T00:00:00Z'),
            
        
    
        
        
            
                "period_end_at": new Date('2026-02-06T23:59:59Z'),
            
        
    
        
        
            
                "prompt_snapshot": "Recommend position sizing adjustments based on drawdown and variance.",
            
        
    
        
        
            
                "output_summary": "Current sizing is stable. Maintain defined risk under 250 and avoid increasing size after a win streak.",
            
        
    
        
        
            
                "consistency_score": 8.1,
            
        
    
        
        
            
                "completed_at": new Date('2026-02-06T16:10:00Z'),
            
        
    
    },
    
];



const AiInsightItemsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "category": "summary",
            
        
    
        
        
            
                "severity": "low",
            
        
    
        
        
            
                "title": "Daily performance summary",
            
        
    
        
        
            
                "detail": "You executed one A+ breakout with controlled risk and minimal hesitation. Maintain this selectivity.",
            
        
    
        
        
            
                // type code here for "relation_many" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "category": "edge",
            
        
    
        
        
            
                "severity": "info",
            
        
    
        
        
            
                "title": "Avoid resistance proximity",
            
        
    
        
        
            
                "detail": "When the next resistance is within 1R, consider scaling out earlier or skipping the entry.",
            
        
    
        
        
            
                // type code here for "relation_many" field
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "category": "pattern",
            
        
    
        
        
            
                "severity": "medium",
            
        
    
        
        
            
                "title": "Sizing discipline maintained",
            
        
    
        
        
            
                "detail": "Keep max loss per position under 250; do not size up immediately after strong winners.",
            
        
    
        
        
            
                // type code here for "relation_many" field
            
        
    
    },
    
];



const AlertRulesData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "rule_type": "overtrading",
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
        
        
            
                "threshold_value": 3.0,
            
        
    
        
        
            
                "threshold_unit": "percent",
            
        
    
        
        
            
                "notes": "Alert if more than 3 discretionary trades in a session.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "rule_type": "drawdown",
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
        
        
            
                "threshold_value": 2.0,
            
        
    
        
        
            
                "threshold_unit": "count",
            
        
    
        
        
            
                "notes": "Notify if intraday drawdown exceeds 2%.",
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "rule_type": "overtrading",
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
        
        
            
                "threshold_value": 250.0,
            
        
    
        
        
            
                "threshold_unit": "days",
            
        
    
        
        
            
                "notes": "Alert if max loss exceeds 250 on any spread.",
            
        
    
    },
    
];



const AlertsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "dismissed",
            
        
    
        
        
            
                "severity": "critical",
            
        
    
        
        
            
                "title": "Session trade count check",
            
        
    
        
        
            
                "message": "Trade count is within session limit. No action required.",
            
        
    
        
        
            
                "triggered_at": new Date('2026-02-03T15:15:30Z'),
            
        
    
        
        
            
                "acknowledged_at": new Date('2026-02-03T15:16:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "new",
            
        
    
        
        
            
                "severity": "info",
            
        
    
        
        
            
                "title": "Drawdown normal",
            
        
    
        
        
            
                "message": "Intraday drawdown remains below 2%.",
            
        
    
        
        
            
                "triggered_at": new Date('2026-02-03T14:40:00Z'),
            
        
    
        
        
            
                "acknowledged_at": new Date('2026-02-03T14:41:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "new",
            
        
    
        
        
            
                "severity": "critical",
            
        
    
        
        
            
                "title": "Risk near threshold",
            
        
    
        
        
            
                "message": "Defined risk is close to 250. Verify spread max loss before adding size.",
            
        
    
        
        
            
                "triggered_at": new Date('2026-02-05T15:41:00Z'),
            
        
    
        
        
            
                "acknowledged_at": new Date('2026-02-06T15:50:00Z'),
            
        
    
    },
    
];



const DashboardWidgetsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Key Metrics Row",
            
        
    
        
        
            
                "widget_type": "goals_progress",
            
        
    
        
        
            
                "config_json": "{metrics:[win_rate,total_pnl,profit_factor,expectancy]}",
            
        
    
        
        
            
                "layout_x": 0,
            
        
    
        
        
            
                "layout_y": 0,
            
        
    
        
        
            
                "layout_w": 12,
            
        
    
        
        
            
                "layout_h": 2,
            
        
    
        
        
            
                "is_visible": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Equity Curve",
            
        
    
        
        
            
                "widget_type": "goals_progress",
            
        
    
        
        
            
                "config_json": "{accountScope:selected,period:90d}",
            
        
    
        
        
            
                "layout_x": 0,
            
        
    
        
        
            
                "layout_y": 2,
            
        
    
        
        
            
                "layout_w": 12,
            
        
    
        
        
            
                "layout_h": 5,
            
        
    
        
        
            
                "is_visible": true,
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "name": "Options Breakdown",
            
        
    
        
        
            
                "widget_type": "duration",
            
        
    
        
        
            
                "config_json": "{groupBy:instrument,metric:pnl_amount}",
            
        
    
        
        
            
                "layout_x": 0,
            
        
    
        
        
            
                "layout_y": 0,
            
        
    
        
        
            
                "layout_w": 12,
            
        
    
        
        
            
                "layout_h": 4,
            
        
    
        
        
            
                "is_visible": true,
            
        
    
    },
    
];



const PdfReportsData = [
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "February Performance Report",
            
        
    
        
        
            
                "report_type": "account_comparison",
            
        
    
        
        
            
                "period_start_at": new Date('2026-02-01T00:00:00Z'),
            
        
    
        
        
            
                "period_end_at": new Date('2026-03-01T23:59:59Z'),
            
        
    
        
        
            
                "status": "ready",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "error_message": "No errors.",
            
        
    
        
        
            
                "generated_at": new Date('2026-02-06T23:10:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "Q1 Crypto Summary",
            
        
    
        
        
            
                "report_type": "weekly",
            
        
    
        
        
            
                "period_start_at": new Date('2026-01-01T00:00:00Z'),
            
        
    
        
        
            
                "period_end_at": new Date('2026-02-06T23:59:59Z'),
            
        
    
        
        
            
                "status": "ready",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "error_message": "No errors.",
            
        
    
        
        
            
                "generated_at": new Date('2026-02-06T23:12:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "title": "Weekly Options Recap",
            
        
    
        
        
            
                "report_type": "account_comparison",
            
        
    
        
        
            
                "period_start_at": new Date('2026-02-02T00:00:00Z'),
            
        
    
        
        
            
                "period_end_at": new Date('2026-02-06T23:59:59Z'),
            
        
    
        
        
            
                "status": "generating",
            
        
    
        
        
            
                // type code here for "files" field
            
        
    
        
        
            
                "error_message": "No errors.",
            
        
    
        
        
            
                "generated_at": new Date('2026-02-06T23:14:00Z'),
            
        
    
    },
    
];




    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            // Similar logic for "relation_many"
        
    

    
    
    
    
    
        
            
            async function associateBillingCustomerWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const BillingCustomer0 = await BillingCustomers.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (BillingCustomer0?.setUser)
                {
                    await
                    BillingCustomer0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const BillingCustomer1 = await BillingCustomers.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (BillingCustomer1?.setUser)
                {
                    await
                    BillingCustomer1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const BillingCustomer2 = await BillingCustomers.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (BillingCustomer2?.setUser)
                {
                    await
                    BillingCustomer2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateSubscriptionWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Subscription0 = await Subscriptions.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Subscription0?.setUser)
                {
                    await
                    Subscription0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Subscription1 = await Subscriptions.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Subscription1?.setUser)
                {
                    await
                    Subscription1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Subscription2 = await Subscriptions.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Subscription2?.setUser)
                {
                    await
                    Subscription2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateTradingAccountWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const TradingAccount0 = await TradingAccounts.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (TradingAccount0?.setUser)
                {
                    await
                    TradingAccount0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const TradingAccount1 = await TradingAccounts.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (TradingAccount1?.setUser)
                {
                    await
                    TradingAccount1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const TradingAccount2 = await TradingAccounts.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (TradingAccount2?.setUser)
                {
                    await
                    TradingAccount2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateSetupWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Setup0 = await Setups.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Setup0?.setUser)
                {
                    await
                    Setup0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Setup1 = await Setups.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Setup1?.setUser)
                {
                    await
                    Setup1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Setup2 = await Setups.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Setup2?.setUser)
                {
                    await
                    Setup2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateTagWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Tag0 = await Tags.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Tag0?.setUser)
                {
                    await
                    Tag0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Tag1 = await Tags.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Tag1?.setUser)
                {
                    await
                    Tag1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Tag2 = await Tags.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Tag2?.setUser)
                {
                    await
                    Tag2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateTradeWithTrading_account() {
            
                const relatedTrading_account0 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const Trade0 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Trade0?.setTrading_account)
                {
                    await
                    Trade0.
                    setTrading_account(relatedTrading_account0);
                }
            
                const relatedTrading_account1 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const Trade1 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Trade1?.setTrading_account)
                {
                    await
                    Trade1.
                    setTrading_account(relatedTrading_account1);
                }
            
                const relatedTrading_account2 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const Trade2 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Trade2?.setTrading_account)
                {
                    await
                    Trade2.
                    setTrading_account(relatedTrading_account2);
                }
            
        }
        
    
        
            
            async function associateTradeWithInstrument() {
            
                const relatedInstrument0 = await Instruments.findOne({
                    offset: Math.floor(Math.random() * (await Instruments.count())),
                });
                const Trade0 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Trade0?.setInstrument)
                {
                    await
                    Trade0.
                    setInstrument(relatedInstrument0);
                }
            
                const relatedInstrument1 = await Instruments.findOne({
                    offset: Math.floor(Math.random() * (await Instruments.count())),
                });
                const Trade1 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Trade1?.setInstrument)
                {
                    await
                    Trade1.
                    setInstrument(relatedInstrument1);
                }
            
                const relatedInstrument2 = await Instruments.findOne({
                    offset: Math.floor(Math.random() * (await Instruments.count())),
                });
                const Trade2 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Trade2?.setInstrument)
                {
                    await
                    Trade2.
                    setInstrument(relatedInstrument2);
                }
            
        }
        
    
        
            
            async function associateTradeWithSetup() {
            
                const relatedSetup0 = await Setups.findOne({
                    offset: Math.floor(Math.random() * (await Setups.count())),
                });
                const Trade0 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Trade0?.setSetup)
                {
                    await
                    Trade0.
                    setSetup(relatedSetup0);
                }
            
                const relatedSetup1 = await Setups.findOne({
                    offset: Math.floor(Math.random() * (await Setups.count())),
                });
                const Trade1 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Trade1?.setSetup)
                {
                    await
                    Trade1.
                    setSetup(relatedSetup1);
                }
            
                const relatedSetup2 = await Setups.findOne({
                    offset: Math.floor(Math.random() * (await Setups.count())),
                });
                const Trade2 = await Trades.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Trade2?.setSetup)
                {
                    await
                    Trade2.
                    setSetup(relatedSetup2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            // Similar logic for "relation_many"
        
    

    
    
    
        
            
            async function associateTradeAttachmentWithTrade() {
            
                const relatedTrade0 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const TradeAttachment0 = await TradeAttachments.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (TradeAttachment0?.setTrade)
                {
                    await
                    TradeAttachment0.
                    setTrade(relatedTrade0);
                }
            
                const relatedTrade1 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const TradeAttachment1 = await TradeAttachments.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (TradeAttachment1?.setTrade)
                {
                    await
                    TradeAttachment1.
                    setTrade(relatedTrade1);
                }
            
                const relatedTrade2 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const TradeAttachment2 = await TradeAttachments.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (TradeAttachment2?.setTrade)
                {
                    await
                    TradeAttachment2.
                    setTrade(relatedTrade2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateTradeRuleWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const TradeRule0 = await TradeRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (TradeRule0?.setUser)
                {
                    await
                    TradeRule0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const TradeRule1 = await TradeRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (TradeRule1?.setUser)
                {
                    await
                    TradeRule1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const TradeRule2 = await TradeRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (TradeRule2?.setUser)
                {
                    await
                    TradeRule2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateTradeRuleCheckWithTrade() {
            
                const relatedTrade0 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const TradeRuleCheck0 = await TradeRuleChecks.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (TradeRuleCheck0?.setTrade)
                {
                    await
                    TradeRuleCheck0.
                    setTrade(relatedTrade0);
                }
            
                const relatedTrade1 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const TradeRuleCheck1 = await TradeRuleChecks.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (TradeRuleCheck1?.setTrade)
                {
                    await
                    TradeRuleCheck1.
                    setTrade(relatedTrade1);
                }
            
                const relatedTrade2 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const TradeRuleCheck2 = await TradeRuleChecks.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (TradeRuleCheck2?.setTrade)
                {
                    await
                    TradeRuleCheck2.
                    setTrade(relatedTrade2);
                }
            
        }
        
    
        
            
            async function associateTradeRuleCheckWithTrade_rule() {
            
                const relatedTrade_rule0 = await TradeRules.findOne({
                    offset: Math.floor(Math.random() * (await TradeRules.count())),
                });
                const TradeRuleCheck0 = await TradeRuleChecks.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (TradeRuleCheck0?.setTrade_rule)
                {
                    await
                    TradeRuleCheck0.
                    setTrade_rule(relatedTrade_rule0);
                }
            
                const relatedTrade_rule1 = await TradeRules.findOne({
                    offset: Math.floor(Math.random() * (await TradeRules.count())),
                });
                const TradeRuleCheck1 = await TradeRuleChecks.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (TradeRuleCheck1?.setTrade_rule)
                {
                    await
                    TradeRuleCheck1.
                    setTrade_rule(relatedTrade_rule1);
                }
            
                const relatedTrade_rule2 = await TradeRules.findOne({
                    offset: Math.floor(Math.random() * (await TradeRules.count())),
                });
                const TradeRuleCheck2 = await TradeRuleChecks.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (TradeRuleCheck2?.setTrade_rule)
                {
                    await
                    TradeRuleCheck2.
                    setTrade_rule(relatedTrade_rule2);
                }
            
        }
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateMoodEntryWithTrade() {
            
                const relatedTrade0 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const MoodEntry0 = await MoodEntries.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (MoodEntry0?.setTrade)
                {
                    await
                    MoodEntry0.
                    setTrade(relatedTrade0);
                }
            
                const relatedTrade1 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const MoodEntry1 = await MoodEntries.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (MoodEntry1?.setTrade)
                {
                    await
                    MoodEntry1.
                    setTrade(relatedTrade1);
                }
            
                const relatedTrade2 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const MoodEntry2 = await MoodEntries.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (MoodEntry2?.setTrade)
                {
                    await
                    MoodEntry2.
                    setTrade(relatedTrade2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateGoalWithTrading_account() {
            
                const relatedTrading_account0 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const Goal0 = await Goals.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Goal0?.setTrading_account)
                {
                    await
                    Goal0.
                    setTrading_account(relatedTrading_account0);
                }
            
                const relatedTrading_account1 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const Goal1 = await Goals.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Goal1?.setTrading_account)
                {
                    await
                    Goal1.
                    setTrading_account(relatedTrading_account1);
                }
            
                const relatedTrading_account2 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const Goal2 = await Goals.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Goal2?.setTrading_account)
                {
                    await
                    Goal2.
                    setTrading_account(relatedTrading_account2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateMilestoneWithGoal() {
            
                const relatedGoal0 = await Goals.findOne({
                    offset: Math.floor(Math.random() * (await Goals.count())),
                });
                const Milestone0 = await Milestones.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Milestone0?.setGoal)
                {
                    await
                    Milestone0.
                    setGoal(relatedGoal0);
                }
            
                const relatedGoal1 = await Goals.findOne({
                    offset: Math.floor(Math.random() * (await Goals.count())),
                });
                const Milestone1 = await Milestones.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Milestone1?.setGoal)
                {
                    await
                    Milestone1.
                    setGoal(relatedGoal1);
                }
            
                const relatedGoal2 = await Goals.findOne({
                    offset: Math.floor(Math.random() * (await Goals.count())),
                });
                const Milestone2 = await Milestones.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Milestone2?.setGoal)
                {
                    await
                    Milestone2.
                    setGoal(relatedGoal2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateWatchlistItemWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const WatchlistItem0 = await WatchlistItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (WatchlistItem0?.setUser)
                {
                    await
                    WatchlistItem0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const WatchlistItem1 = await WatchlistItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (WatchlistItem1?.setUser)
                {
                    await
                    WatchlistItem1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const WatchlistItem2 = await WatchlistItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (WatchlistItem2?.setUser)
                {
                    await
                    WatchlistItem2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
            
            async function associateWatchlistItemWithInstrument() {
            
                const relatedInstrument0 = await Instruments.findOne({
                    offset: Math.floor(Math.random() * (await Instruments.count())),
                });
                const WatchlistItem0 = await WatchlistItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (WatchlistItem0?.setInstrument)
                {
                    await
                    WatchlistItem0.
                    setInstrument(relatedInstrument0);
                }
            
                const relatedInstrument1 = await Instruments.findOne({
                    offset: Math.floor(Math.random() * (await Instruments.count())),
                });
                const WatchlistItem1 = await WatchlistItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (WatchlistItem1?.setInstrument)
                {
                    await
                    WatchlistItem1.
                    setInstrument(relatedInstrument1);
                }
            
                const relatedInstrument2 = await Instruments.findOne({
                    offset: Math.floor(Math.random() * (await Instruments.count())),
                });
                const WatchlistItem2 = await WatchlistItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (WatchlistItem2?.setInstrument)
                {
                    await
                    WatchlistItem2.
                    setInstrument(relatedInstrument2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateCsvImportJobWithTrading_account() {
            
                const relatedTrading_account0 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const CsvImportJob0 = await CsvImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (CsvImportJob0?.setTrading_account)
                {
                    await
                    CsvImportJob0.
                    setTrading_account(relatedTrading_account0);
                }
            
                const relatedTrading_account1 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const CsvImportJob1 = await CsvImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (CsvImportJob1?.setTrading_account)
                {
                    await
                    CsvImportJob1.
                    setTrading_account(relatedTrading_account1);
                }
            
                const relatedTrading_account2 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const CsvImportJob2 = await CsvImportJobs.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (CsvImportJob2?.setTrading_account)
                {
                    await
                    CsvImportJob2.
                    setTrading_account(relatedTrading_account2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateCsvImportRowErrorWithCsv_import_job() {
            
                const relatedCsv_import_job0 = await CsvImportJobs.findOne({
                    offset: Math.floor(Math.random() * (await CsvImportJobs.count())),
                });
                const CsvImportRowError0 = await CsvImportRowErrors.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (CsvImportRowError0?.setCsv_import_job)
                {
                    await
                    CsvImportRowError0.
                    setCsv_import_job(relatedCsv_import_job0);
                }
            
                const relatedCsv_import_job1 = await CsvImportJobs.findOne({
                    offset: Math.floor(Math.random() * (await CsvImportJobs.count())),
                });
                const CsvImportRowError1 = await CsvImportRowErrors.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (CsvImportRowError1?.setCsv_import_job)
                {
                    await
                    CsvImportRowError1.
                    setCsv_import_job(relatedCsv_import_job1);
                }
            
                const relatedCsv_import_job2 = await CsvImportJobs.findOne({
                    offset: Math.floor(Math.random() * (await CsvImportJobs.count())),
                });
                const CsvImportRowError2 = await CsvImportRowErrors.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (CsvImportRowError2?.setCsv_import_job)
                {
                    await
                    CsvImportRowError2.
                    setCsv_import_job(relatedCsv_import_job2);
                }
            
        }
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateBrokerConnectionWithTrading_account() {
            
                const relatedTrading_account0 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const BrokerConnection0 = await BrokerConnections.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (BrokerConnection0?.setTrading_account)
                {
                    await
                    BrokerConnection0.
                    setTrading_account(relatedTrading_account0);
                }
            
                const relatedTrading_account1 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const BrokerConnection1 = await BrokerConnections.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (BrokerConnection1?.setTrading_account)
                {
                    await
                    BrokerConnection1.
                    setTrading_account(relatedTrading_account1);
                }
            
                const relatedTrading_account2 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const BrokerConnection2 = await BrokerConnections.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (BrokerConnection2?.setTrading_account)
                {
                    await
                    BrokerConnection2.
                    setTrading_account(relatedTrading_account2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateTradeSyncRunWithBroker_connection() {
            
                const relatedBroker_connection0 = await BrokerConnections.findOne({
                    offset: Math.floor(Math.random() * (await BrokerConnections.count())),
                });
                const TradeSyncRun0 = await TradeSyncRuns.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (TradeSyncRun0?.setBroker_connection)
                {
                    await
                    TradeSyncRun0.
                    setBroker_connection(relatedBroker_connection0);
                }
            
                const relatedBroker_connection1 = await BrokerConnections.findOne({
                    offset: Math.floor(Math.random() * (await BrokerConnections.count())),
                });
                const TradeSyncRun1 = await TradeSyncRuns.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (TradeSyncRun1?.setBroker_connection)
                {
                    await
                    TradeSyncRun1.
                    setBroker_connection(relatedBroker_connection1);
                }
            
                const relatedBroker_connection2 = await BrokerConnections.findOne({
                    offset: Math.floor(Math.random() * (await BrokerConnections.count())),
                });
                const TradeSyncRun2 = await TradeSyncRuns.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (TradeSyncRun2?.setBroker_connection)
                {
                    await
                    TradeSyncRun2.
                    setBroker_connection(relatedBroker_connection2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateAiInsightRunWithTrading_account() {
            
                const relatedTrading_account0 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const AiInsightRun0 = await AiInsightRuns.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (AiInsightRun0?.setTrading_account)
                {
                    await
                    AiInsightRun0.
                    setTrading_account(relatedTrading_account0);
                }
            
                const relatedTrading_account1 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const AiInsightRun1 = await AiInsightRuns.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (AiInsightRun1?.setTrading_account)
                {
                    await
                    AiInsightRun1.
                    setTrading_account(relatedTrading_account1);
                }
            
                const relatedTrading_account2 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const AiInsightRun2 = await AiInsightRuns.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (AiInsightRun2?.setTrading_account)
                {
                    await
                    AiInsightRun2.
                    setTrading_account(relatedTrading_account2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateAiInsightItemWithAi_insight_run() {
            
                const relatedAi_insight_run0 = await AiInsightRuns.findOne({
                    offset: Math.floor(Math.random() * (await AiInsightRuns.count())),
                });
                const AiInsightItem0 = await AiInsightItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (AiInsightItem0?.setAi_insight_run)
                {
                    await
                    AiInsightItem0.
                    setAi_insight_run(relatedAi_insight_run0);
                }
            
                const relatedAi_insight_run1 = await AiInsightRuns.findOne({
                    offset: Math.floor(Math.random() * (await AiInsightRuns.count())),
                });
                const AiInsightItem1 = await AiInsightItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (AiInsightItem1?.setAi_insight_run)
                {
                    await
                    AiInsightItem1.
                    setAi_insight_run(relatedAi_insight_run1);
                }
            
                const relatedAi_insight_run2 = await AiInsightRuns.findOne({
                    offset: Math.floor(Math.random() * (await AiInsightRuns.count())),
                });
                const AiInsightItem2 = await AiInsightItems.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (AiInsightItem2?.setAi_insight_run)
                {
                    await
                    AiInsightItem2.
                    setAi_insight_run(relatedAi_insight_run2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
            // Similar logic for "relation_many"
        
    

    
    
    
        
            
            async function associateAlertRuleWithTrading_account() {
            
                const relatedTrading_account0 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const AlertRule0 = await AlertRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (AlertRule0?.setTrading_account)
                {
                    await
                    AlertRule0.
                    setTrading_account(relatedTrading_account0);
                }
            
                const relatedTrading_account1 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const AlertRule1 = await AlertRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (AlertRule1?.setTrading_account)
                {
                    await
                    AlertRule1.
                    setTrading_account(relatedTrading_account1);
                }
            
                const relatedTrading_account2 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const AlertRule2 = await AlertRules.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (AlertRule2?.setTrading_account)
                {
                    await
                    AlertRule2.
                    setTrading_account(relatedTrading_account2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateAlertWithAlert_rule() {
            
                const relatedAlert_rule0 = await AlertRules.findOne({
                    offset: Math.floor(Math.random() * (await AlertRules.count())),
                });
                const Alert0 = await Alerts.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Alert0?.setAlert_rule)
                {
                    await
                    Alert0.
                    setAlert_rule(relatedAlert_rule0);
                }
            
                const relatedAlert_rule1 = await AlertRules.findOne({
                    offset: Math.floor(Math.random() * (await AlertRules.count())),
                });
                const Alert1 = await Alerts.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Alert1?.setAlert_rule)
                {
                    await
                    Alert1.
                    setAlert_rule(relatedAlert_rule1);
                }
            
                const relatedAlert_rule2 = await AlertRules.findOne({
                    offset: Math.floor(Math.random() * (await AlertRules.count())),
                });
                const Alert2 = await Alerts.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Alert2?.setAlert_rule)
                {
                    await
                    Alert2.
                    setAlert_rule(relatedAlert_rule2);
                }
            
        }
        
    
        
            
            async function associateAlertWithTrade() {
            
                const relatedTrade0 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const Alert0 = await Alerts.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Alert0?.setTrade)
                {
                    await
                    Alert0.
                    setTrade(relatedTrade0);
                }
            
                const relatedTrade1 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const Alert1 = await Alerts.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Alert1?.setTrade)
                {
                    await
                    Alert1.
                    setTrade(relatedTrade1);
                }
            
                const relatedTrade2 = await Trades.findOne({
                    offset: Math.floor(Math.random() * (await Trades.count())),
                });
                const Alert2 = await Alerts.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Alert2?.setTrade)
                {
                    await
                    Alert2.
                    setTrade(relatedTrade2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associateDashboardWidgetWithUser() {
            
                const relatedUser0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const DashboardWidget0 = await DashboardWidgets.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (DashboardWidget0?.setUser)
                {
                    await
                    DashboardWidget0.
                    setUser(relatedUser0);
                }
            
                const relatedUser1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const DashboardWidget1 = await DashboardWidgets.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (DashboardWidget1?.setUser)
                {
                    await
                    DashboardWidget1.
                    setUser(relatedUser1);
                }
            
                const relatedUser2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const DashboardWidget2 = await DashboardWidgets.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (DashboardWidget2?.setUser)
                {
                    await
                    DashboardWidget2.
                    setUser(relatedUser2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
            
            async function associatePdfReportWithTrading_account() {
            
                const relatedTrading_account0 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const PdfReport0 = await PdfReports.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (PdfReport0?.setTrading_account)
                {
                    await
                    PdfReport0.
                    setTrading_account(relatedTrading_account0);
                }
            
                const relatedTrading_account1 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const PdfReport1 = await PdfReports.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (PdfReport1?.setTrading_account)
                {
                    await
                    PdfReport1.
                    setTrading_account(relatedTrading_account1);
                }
            
                const relatedTrading_account2 = await TradingAccounts.findOne({
                    offset: Math.floor(Math.random() * (await TradingAccounts.count())),
                });
                const PdfReport2 = await PdfReports.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (PdfReport2?.setTrading_account)
                {
                    await
                    PdfReport2.
                    setTrading_account(relatedTrading_account2);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    


module.exports = {
    up: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
                
                await BillingCustomers.bulkCreate(BillingCustomersData);
                
            
            
                
                await Subscriptions.bulkCreate(SubscriptionsData);
                
            
            
                
                await TradingAccounts.bulkCreate(TradingAccountsData);
                
            
            
                
                await Instruments.bulkCreate(InstrumentsData);
                
            
            
                
                await Setups.bulkCreate(SetupsData);
                
            
            
                
                await Tags.bulkCreate(TagsData);
                
            
            
                
                await Trades.bulkCreate(TradesData);
                
            
            
                
                await TradeAttachments.bulkCreate(TradeAttachmentsData);
                
            
            
                
                await TradeRules.bulkCreate(TradeRulesData);
                
            
            
                
                await TradeRuleChecks.bulkCreate(TradeRuleChecksData);
                
            
            
                
                await MoodEntries.bulkCreate(MoodEntriesData);
                
            
            
                
                await Goals.bulkCreate(GoalsData);
                
            
            
                
                await Milestones.bulkCreate(MilestonesData);
                
            
            
                
                await WatchlistItems.bulkCreate(WatchlistItemsData);
                
            
            
                
                await EconomicEvents.bulkCreate(EconomicEventsData);
                
            
            
                
                await CsvImportJobs.bulkCreate(CsvImportJobsData);
                
            
            
                
                await CsvImportRowErrors.bulkCreate(CsvImportRowErrorsData);
                
            
            
                
                await BrokerConnections.bulkCreate(BrokerConnectionsData);
                
            
            
                
                await TradeSyncRuns.bulkCreate(TradeSyncRunsData);
                
            
            
                
                await AiInsightRuns.bulkCreate(AiInsightRunsData);
                
            
            
                
                await AiInsightItems.bulkCreate(AiInsightItemsData);
                
            
            
                
                await AlertRules.bulkCreate(AlertRulesData);
                
            
            
                
                await Alerts.bulkCreate(AlertsData);
                
            
            
                
                await DashboardWidgets.bulkCreate(DashboardWidgetsData);
                
            
            
                
                await PdfReports.bulkCreate(PdfReportsData);
                
            
            await Promise.all([
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
            
                
                
                
                
                    
                        
                        await associateBillingCustomerWithUser(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateSubscriptionWithUser(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateTradingAccountWithUser(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateSetupWithUser(),
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateTagWithUser(),
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateTradeWithTrading_account(),
                    
                
                    
                        
                        await associateTradeWithInstrument(),
                    
                
                    
                        
                        await associateTradeWithSetup(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
            
                
                
                    
                        
                        await associateTradeAttachmentWithTrade(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateTradeRuleWithUser(),
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateTradeRuleCheckWithTrade(),
                    
                
                    
                        
                        await associateTradeRuleCheckWithTrade_rule(),
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateMoodEntryWithTrade(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateGoalWithTrading_account(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateMilestoneWithGoal(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateWatchlistItemWithUser(),
                    
                
                    
                        
                        await associateWatchlistItemWithInstrument(),
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateCsvImportJobWithTrading_account(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateCsvImportRowErrorWithCsv_import_job(),
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateBrokerConnectionWithTrading_account(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateTradeSyncRunWithBroker_connection(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateAiInsightRunWithTrading_account(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateAiInsightItemWithAi_insight_run(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
            
                
                
                    
                        
                        await associateAlertRuleWithTrading_account(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateAlertWithAlert_rule(),
                    
                
                    
                        
                        await associateAlertWithTrade(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associateDashboardWidgetWithUser(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                        
                        await associatePdfReportWithTrading_account(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            ]);
        
    },

    down: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
            await queryInterface.bulkDelete('billing_customers', null, {});
            
            
            await queryInterface.bulkDelete('subscriptions', null, {});
            
            
            await queryInterface.bulkDelete('trading_accounts', null, {});
            
            
            await queryInterface.bulkDelete('instruments', null, {});
            
            
            await queryInterface.bulkDelete('setups', null, {});
            
            
            await queryInterface.bulkDelete('tags', null, {});
            
            
            await queryInterface.bulkDelete('trades', null, {});
            
            
            await queryInterface.bulkDelete('trade_attachments', null, {});
            
            
            await queryInterface.bulkDelete('trade_rules', null, {});
            
            
            await queryInterface.bulkDelete('trade_rule_checks', null, {});
            
            
            await queryInterface.bulkDelete('mood_entries', null, {});
            
            
            await queryInterface.bulkDelete('goals', null, {});
            
            
            await queryInterface.bulkDelete('milestones', null, {});
            
            
            await queryInterface.bulkDelete('watchlist_items', null, {});
            
            
            await queryInterface.bulkDelete('economic_events', null, {});
            
            
            await queryInterface.bulkDelete('csv_import_jobs', null, {});
            
            
            await queryInterface.bulkDelete('csv_import_row_errors', null, {});
            
            
            await queryInterface.bulkDelete('broker_connections', null, {});
            
            
            await queryInterface.bulkDelete('trade_sync_runs', null, {});
            
            
            await queryInterface.bulkDelete('ai_insight_runs', null, {});
            
            
            await queryInterface.bulkDelete('ai_insight_items', null, {});
            
            
            await queryInterface.bulkDelete('alert_rules', null, {});
            
            
            await queryInterface.bulkDelete('alerts', null, {});
            
            
            await queryInterface.bulkDelete('dashboard_widgets', null, {});
            
            
            await queryInterface.bulkDelete('pdf_reports', null, {});
            
        
    },
};