-- Shared DB SAFE verify pass

SELECT DATABASE() AS verified_database;

SELECT
  SUM(company_id IS NULL OR company_id = 0) AS users_missing_company,
  SUM(staff_code IS NULL OR TRIM(staff_code) = '') AS users_missing_staff_code,
  SUM(full_name IS NULL OR TRIM(full_name) = '') AS users_missing_full_name
FROM users;

SELECT COUNT(*) AS work_sessions_missing_company
FROM work_sessions
WHERE company_id IS NULL OR company_id = 0;

SELECT COUNT(*) AS work_session_events_missing_company
FROM work_session_events
WHERE company_id IS NULL OR company_id = 0;

SELECT COUNT(*) AS work_session_events_missing_user_id
FROM work_session_events
WHERE user_id IS NULL OR user_id = 0;

SELECT COUNT(*) AS api_sessions_missing_company
FROM api_sessions
WHERE company_id IS NULL OR company_id = 0;

SELECT COUNT(*) AS worksites_missing_company
FROM worksites
WHERE company_id IS NULL OR company_id = 0;

SELECT COUNT(*) AS user_worksites_missing_company
FROM user_worksites
WHERE company_id IS NULL OR company_id = 0;

SELECT COUNT(*) AS location_logs_missing_company
FROM location_logs
WHERE company_id IS NULL OR company_id = 0;

SELECT COUNT(*) AS location_stops_missing_company
FROM location_stops
WHERE company_id IS NULL OR company_id = 0;

SELECT COUNT(*) AS admin_audit_log_missing_company
FROM admin_audit_log
WHERE company_id IS NULL OR company_id = 0;

SHOW INDEX FROM users;
SHOW INDEX FROM work_sessions;
SHOW INDEX FROM work_session_events;
