# Moving a store

A store lives in one place at a time, the repo or the server; the server's record is the truth (`GET /v1/projects/{p}/store`: `location: repo|server|moving`, `movedAt`).

Both directions need the admin token.

- `tkt store move --to server` (in the repo whose `.aitodo.yaml` names the store): needs `.aitodo/server.yaml`, a `tkt doctor` without errors (warnings pass), nothing uncommitted (`ERR_BAD_REQUEST`), no live claim (`ERR_ALREADY_CLAIMED`; `--force-claims` drops the leases), no open decomposition (`ERR_CONFIRM_REQUIRED`; `--force-decompositions` drops them).
- `tkt store move --to repo --dir .tickets` (where `.aitodo.yaml` says `store: server`): `--dir` must not exist, or be empty; commit it and `.aitodo.yaml`.

## Details

- Merge open branches first: their tickets are not in the move. After `--to server`, commit what it prints.
- **To the server:** the store needs its own directory. The client uploads the committed files, with the history (a git bundle) when the store dir is the root of its own repository; the server checks with `tkt doctor` while `moving`, then `server`. Only then the client removes the local dir and rewrites `.aitodo.yaml` to `store: server`. A failure leaves `repo` and the local store untouched.
- **Back:** the server freezes the store (`moving`: every `/cli` call gets 409 `ERR_STORE_MOVING`), the client writes it, then `repo`, and the server archives its copy to `stores/.archive/<project>-<date>` (never deleted); `.aitodo.yaml` says `workspaceDir: <dir>`. A failed release removes the dir: run it again; a crash after the release: the same command only rewrites the pointer. Open decompositions refuse here too; forced, they stay in the archive.
- **Half-done:** the operator runs `tkt operator store-unfreeze <project> --server https://tkt.ideathon.me` (back to `server`) or `tkt operator store-release <project> --server https://tkt.ideathon.me` (`repo`, archived); each leaves an audit line.
- **Guards:** `/cli` runs only while `server`. A clone still writing its old local store gets 409 `ERR_STORE_LOCATION` ("this local copy is stale") once it asks for an id or a claim; `tkt doctor` warns `STALE_LOCAL_STORE` (skipped offline or without a token), also when a branch merged later brings the store dir back.
- **REST (admin):** `POST /v1/projects/{p}/store:import` `{tar, bundle?, forceClaims?}` (base64; at most 100 MB together, else 413 `ERR_PAYLOAD_TOO_LARGE`; the body is read only after the admin token check; a broken store 400 `ERR_BAD_REQUEST`) → `{location, storeVersion, movedAt, history, files}`; `POST /v1/projects/{p}/store:export` and `POST /v1/projects/{p}/store:release` take `{forceDecompositions?}`.

## Commands on this page

- [`tkt store move`](/en/docs/reference/commands/maintenance.md#tkt-store-move): Move the store between this repo and the server; it lives in one place at a time (#153)

## Related

- Error code · 409: [`ERR_STORE_MOVING`](/en/docs/reference/errors.md#ERR_STORE_MOVING): The store is being moved between repo and server; frozen until it lands
- Error code · 409: [`ERR_STORE_LOCATION`](/en/docs/reference/errors.md#ERR_STORE_LOCATION): The store is not where the call needs it (repo or server)
- Doctor · warning: [`STALE_LOCAL_STORE`](/en/docs/reference/doctor.md#doctor-STALE_LOCAL_STORE): A local store beside store: server, or the server says the store moved: a stale copy
