-- West Coast Pest / shared DB safe preflight
-- Run this first on the CURRENT shared database.

SELECT DATABASE() AS current_database;

-- Core tables check
SELECT 'users' AS table_name, COUNT(*) AS row_count FROM users
UNION ALL
SELECT 'work_sessions', COUNT(*) FROM work_sessions
UNION ALL
SELECT 'work_session_events', COUNT(*) FROM work_session_events;

-- users identity readiness
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;

-- Snapshot of current structure for key tables
SHOW COLUMNS FROM users;
SHOW COLUMNS FROM work_sessions;
SHOW COLUMNS FROM work_session_events;

-- Optional tables: run only if they exist in your DB
-- SHOW COLUMNS FROM api_sessions;
-- SHOW COLUMNS FROM worksites;
-- SHOW COLUMNS FROM user_worksites;
-- SHOW COLUMNS FROM location_logs;
-- SHOW COLUMNS FROM location_stops;
-- SHOW COLUMNS FROM admin_audit_log;
