SELECT table_name FROM information_schema.tables
WHERE table_schema = DATABASE() AND table_name IN (
  'qipai_device_alerts', 'qipai_device_channels', 'qipai_device_links',
  'qipai_device_status_snapshots', 'qipai_device_maintenance_records'
) ORDER BY table_name;

SELECT column_name FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'qipai_devices'
  AND column_name IN (
    'iccid', 'model', 'firmware_version', 'signal_strength', 'capabilities',
    'state_snapshot', 'last_heartbeat_at', 'maintenance_status'
  ) ORDER BY column_name;

SELECT table_name, index_name FROM information_schema.statistics
WHERE table_schema = DATABASE()
  AND ((table_name = 'qipai_device_channels'
        AND index_name IN (
          'uq_qipai_device_channel_code', 'uq_qipai_device_channel_target'
        ))
    OR (table_name = 'qipai_device_links'
        AND index_name IN (
          'uq_qipai_device_link_child', 'uq_qipai_device_link_sub',
          'uq_qipai_device_link_room_type'
        )))
GROUP BY table_name, index_name ORDER BY table_name, index_name;

SELECT code FROM qipai_permissions
WHERE code IN ('device.read', 'device.write') ORDER BY code;

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