SELECT table_name FROM information_schema.tables
WHERE table_schema = DATABASE() AND table_name IN (
  'qipai_iot_commands', 'qipai_iot_device_events', 'qipai_iot_dead_letters'
) ORDER BY table_name;

SELECT table_name, index_name FROM information_schema.statistics
WHERE table_schema = DATABASE()
  AND ((table_name = 'qipai_iot_commands'
        AND index_name = 'uq_qipai_iot_command_id')
    OR (table_name = 'qipai_iot_device_events'
        AND index_name = 'uq_qipai_iot_event_dedup')
    OR (table_name = 'qipai_iot_dead_letters'
        AND index_name = 'uq_qipai_iot_dead_dedup'))
GROUP BY table_name, index_name ORDER BY table_name;

SELECT column_name FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'qipai_iot_commands'
  AND column_name IN (
    'command_id', 'status', 'request_payload', 'response_payload',
    'retry_count', 'published_at', 'acknowledged_at', 'expires_at', 'failure_code'
  ) ORDER BY column_name;

SELECT version, name FROM qipai_schema_migrations WHERE version = '2026062220';
