# Tenant & Branch Migration

The previous schema stored a `company_id` on many tables. This ID now maps to a
`tenant_id` and `branch_id` pair.

Existing records in `companies` become branch records. Each company row should be
copied to the `branches` table with its original `id` and a `tenant_id` pointing
to the appropriate entry in the `tenants` table (create one tenant for each
organisation if needed).  All foreign key references that previously pointed to
`companies.id` should now reference the new `branches.id` column while also
setting `tenant_id` to the branch's tenant.

Update application configuration so the session/JWT stores `tenant_id` and
`branch_id`. During migration you can derive these values by looking up the
original `company_id` on employees and users and mapping it to the new branch.
