# Operations

> Backups, upgrades, migrations, rotation and the gate that runs before every release.

URL: https://chatwork.io/en/docs/operations
Section: Operate

## The gate

`scripts/check.sh` runs the whole platform's checks from a clean checkout:

1. bridge unit tests (Python 3.12 via `uv`, no network),
2. bridge PostgreSQL tier on a throwaway cluster: `pg_ctl` when installed, otherwise an embedded PostgreSQL 16 with pgvector (`scripts/pg_embedded.py`), so Chatwork Router's SQL is always exercised,
3. compile check and the 200-line budget (new files ≤ 200 lines; legacy files may only shrink),
4. registry validation, and the routing and pricing conformance fixtures in Python and TypeScript,
5. site type-check and production build,
6. secret scan and a check that no `.env` is tracked.

Nothing merges red.

## Backups

Before every deploy: Redis `SAVE` and copy of `dump.rdb`, `pg_dumpall` of PostgreSQL (both databases), copies of `docker-compose.yml` and `.env`, all under `backups/` with `chmod 600`. Test a restore quarterly.

## Upgrading the platform

```bash
git pull
docker compose -f infra/docker-compose.yml build bridge site
docker compose -f infra/docker-compose.yml up -d
docker compose -f infra/docker-compose.yml exec bridge python -m storage.migrate
docker compose -f infra/docker-compose.yml exec bridge python -m cloudrag.seed
```

Migrations are idempotent and run under an advisory lock; the seed upserts agents by slug and version. Re-run `cloudrag.seed --embed` after changing an agent's intents.

## Upgrading chatwork

Change the pinned tag in `infra/docker-compose.yml`, back up, `docker compose pull chatwoot-rails chatwoot-sidekiq && docker compose up -d chatwoot-rails chatwoot-sidekiq`, check `https://chat.<domain>/api`. Record the new pair in the version matrix.

## Rotation

`DOT_ADMIN_API_KEY`, `CHATWOOT_WEBHOOK_SECRET` (update the agent-bot URL in chatwork) and `DOT_WIDGET_SIGNING_KEY` rotate by editing `.env` and restarting the bridge; widget sessions re-issue themselves. Rotating `DOT_CREDENTIALS_KEY` requires re-connecting every channel and re-enrolling MFA, so plan it.

## Monitoring minimums

`GET /health` is liveness: `{status, service, version}`; with the admin key it adds configuration and tenant count. `GET /ready` is readiness for the orchestrator: `200` only when Redis answers (and PostgreSQL, when it is the system of record); the Compose health check uses it. Watch `GET /api/v1/admin/events/stats` for `failed` and `dead` counts, and `GET /api/v1/tenants/{slug}/cloudrag/decisions` for routing latency.
