-- Production diagnosis for orders.company_id (run in phpMyAdmin or mysql CLI)
-- Expected when column is missing: empty result for SHOW COLUMNS on orders

SHOW COLUMNS FROM orders LIKE 'company_id';
SHOW COLUMNS FROM order_items LIKE 'company_id';

SELECT id, name, domain FROM companies WHERE id = 8143;
SELECT id, company_id, code, hostname FROM channels WHERE id = 8108;

SELECT COUNT(*) AS orders_missing_company
FROM orders o
LEFT JOIN channels c ON c.id = o.channel_id
WHERE o.company_id IS NULL OR o.company_id = 0;

SELECT COUNT(*) AS company_8143_orders_mismatch
FROM orders o
INNER JOIN channels c ON c.id = o.channel_id
WHERE c.company_id = 8143
  AND (o.company_id IS NULL OR o.company_id != 8143);
