WEST COAST PEST - SHARED DB SAFE PACKAGE

Purpose
- Use the CURRENT single database.
- Keep the current live/test code usable.
- Prepare the DB for the new /pest rebuild.
- Avoid destructive changes.

IMPORTANT
- This package is designed for a SHARED DATABASE transition.
- It is additive and compatibility-first.
- It does NOT drop columns, rename columns, or force risky NOT NULL/foreign key rules.

RUN ORDER
1. 00-preflight-checks.sql
2. 01-db-aligned-tenant-foundation-safe.sql
3. 02-db-aligned-west-coast-pest-backfill-safe.sql
4. 03-db-aligned-safe-indexes-only.sql
5. 04-db-aligned-verify-safe.sql

WHAT THIS PACKAGE DOES
- Adds missing company_id columns where needed.
- Makes sure users has company_id, staff_code, full_name.
- Backfills company_id into core operational tables.
- Backfills work_session_events.user_id from work_sessions.
- Adds safe indexes only.

WHAT THIS PACKAGE DOES NOT DO YET
- No drops
- No renames
- No NOT NULL hardening on shared live tables
- No foreign keys on new company_id columns
- No legacy cleanup

EXPECTED VERIFY RESULT
You want these at 0:
- users_missing_company
- users_missing_staff_code
- users_missing_full_name
- work_sessions_missing_company
- work_session_events_missing_company
- work_session_events_missing_user_id
- api_sessions_missing_company
- worksites_missing_company
- user_worksites_missing_company
- location_logs_missing_company
- location_stops_missing_company
- admin_audit_log_missing_company

IF A TABLE DOES NOT EXIST
Some environments may not yet have every optional table.
If a script fails because a table does not exist, stop and tell ChatGPT which table is missing.
A trimmed package can then be generated for your exact DB.
