# Staging geo datasets (Go-owned schema)

Staging's geo tables are created by the Go migrations (`ad.com-dsp/src/storage/mysql/migrations`),
which store codes rather than names. These files override the defaults in `data/geo` when the
loader runs with `USE_SHARED_DB=true`. All columns are kept and filled; only `value` differs.

| File                | `value` here            | `value` in `data/geo` | Other columns                                         |
| ------------------- | ----------------------- | --------------------- | ----------------------------------------------------- |
| `geo_countries.csv` | ISO alpha-2: `US`       | `United States`       | unchanged (`label`, `alpha2`, `alpha3`, ...)          |
| `geo_states.csv`    | ISO 3166-2 suffix: `FL` | `Florida`             | unchanged (`code` = `US-FL`, `label`, `country_code`) |

Cities and DMAs use the shared files: Go's city key is `(country_code, value)`, so the
`"Miami, FL"` value keeps same-name cities in one country apart (`name` holds `Miami`).

Regenerate after rebuilding `data/geo`: `value` = `alpha2` for countries, and `value` = the part
of `code` after the first `-` for states. Each state `(country_code, value)` must stay unique.

## Load on staging

Requires Go migration `0003_api_compat` (it widens city columns; some city names exceed 64 characters).

```bash
npm run db:generate      # with USE_SHARED_DB=true
npm run geo:load:dry-run   # preview, no writes
npm run geo:load           # or: npm run geo:load -- countries states
```

The loader updates Go's starter rows in place, deactivates rows from older name-format loads,
and never deletes rows or touches saved targeting.
