SELECT table_name
FROM information_schema.tables
WHERE table_schema = DATABASE()
  AND table_name = 'qipai_business_daily_summaries';

SELECT column_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
  AND table_name = 'qipai_business_daily_summaries'
  AND column_name IN (
    'business_date', 'timezone', 'order_count', 'customer_count',
    'used_minutes', 'capacity_minutes', 'room_gross_cents',
    'room_refund_cents', 'product_gross_cents', 'product_refund_cents',
    'cleaning_cost_cents', 'wechat_net_cents', 'balance_net_cents',
    'package_net_cents', 'group_buy_net_cents', 'other_net_cents',
    'source_checksum', 'calculated_at'
  );

SELECT index_name
FROM information_schema.statistics
WHERE table_schema = DATABASE()
  AND table_name = 'qipai_business_daily_summaries'
  AND index_name IN (
    'uq_qipai_business_daily_summary_date',
    'idx_qipai_business_daily_summary_tenant_date'
  );

SELECT code
FROM qipai_permissions
WHERE code IN ('report.read', 'report.export', 'report.manage');

SELECT COUNT(*) AS configured_role_permissions
FROM qipai_role_permissions rp
INNER JOIN qipai_roles r ON r.id = rp.role_id AND r.tenant_id = rp.tenant_id
INNER JOIN qipai_permissions p ON p.id = rp.permission_id
WHERE r.code IN ('STORE_ADMIN', 'TENANT_ADMIN', 'PLATFORM_ADMIN')
  AND p.code IN ('report.read', 'report.export', 'report.manage');

SELECT version, name
FROM qipai_schema_migrations
WHERE version = '2026081111' AND name = 'm10b_business_reports';
