# Store migration

Brings a store written by an older `tkt` up to this one's rules, rule-based (no AI): `tkt reorg` proposes interactively, `tkt reorg --plan plan.yaml` writes a plan file, `tkt reorg apply plan.yaml` applies it.

The store's data level is `schemaVersion` in `.aitodo/config.yaml`: `tkt init` writes the current one, `tkt doctor` names an older store (`STORE_OUTDATED`, `→ tkt reorg`), and reorg raises it once no migration proposal is left (each applied or dismissed).

- All or nothing: the whole plan is validated, a backup goes to `.aitodo/backups/reorg-<timestamp>/` (git-ignored), any failure restores every file. `tkt reorg restore` undoes it, the level too.
- `tkt reorg apply plan.yaml --dry-run` runs it on a throwaway copy and prints the bundle impact on every ticket that reads an item it touches (of any type). A plan that makes a ticket lose a critical gotcha, a ref its body names or an own ref is refused: `ERR_REORG_CONTEXT_LOSS`, nothing written (`--accept-context-loss` overrides).

## Details

Each proposal has a stable `id` (e.g. `retired-status:SG-12`), a reason, a confidence and options; `choice` is the option index (from 0), `skip` (later) or `dismiss` (never again). Kinds, the first seven on an older store only: `dropped-affects` (keep, or record as dropped, the `affects` a superseding or amending decision left out), `text-supersession` (a replacement named only in text: `supersedes` or `amends`), `doc-header` (a doc's status line names a superseded decision: mark it or name the successor), `dangling-affects` (an `affects` target that names nothing), `bind-mention` (an item named in text with no edge, grouped by the named item, bound by the declared edge; a doc's mention of a decision becomes the decision's `affects`), `retired-status` (a stored `blocked`: the status the work is in), `decision-view` (the old generated decision-log doc is deleted: a row ref points at its decision, a ref to the whole table goes, the text mentions of open items are listed for a hand edit), `typed-frontmatter` (a `description` for docs and gotchas without one).

- What a write and the bundle flag (`UNLINKED_ITEM`, `POSSIBLE_DUPLICATE`, `REPEATED_PARAGRAPH`, `LONE_GROUP_MEMBER`, `tkt suggest refs --group`, `LIFECYCLE`) is no reorg proposal: `--only` with an old kind names its new place; a plan change reorg no longer makes (`move_ticket`, `add_note` …) names its command.
- It never changes a closed item's content.
- Interactive: `a` accept, `1-n` an alternative, `e` edit in `$EDITOR`, `s` skip, `d` dismiss for good, `q` quit; then one confirmation (with loss, `--yes` without `--accept-context-loss` is refused).
- `tkt reorg --impact`: each proposal's own impact (plan file, JSON, interactive), not additive; apply never trusts it and measures again.
- `tkt reorg dismiss <id>` (`--undo`) hides a proposal (`reviews/_store.yaml`); the last migration proposal dismissed raises the level. `tkt reorg backups` lists the backups. `tkt reorg restore` (default: the latest) loses later edits, so it asks first.
- A write outside tkt (an editor, a merge) is caught by `tkt index rebuild`, not by reorg: it names the open reviews (`tkt review`).

## Commands on this page

- [`tkt reorg`](/en/docs/reference/commands/maintenance.md#tkt-reorg): Migrate an old store: propose what brings it up to this tkt's rules, and apply the accepted proposals (all-or-nothing, with a backup)
- [`tkt reorg apply`](/en/docs/reference/commands/maintenance.md#tkt-reorg-apply): Apply a plan file all-or-nothing: every chosen option, or nothing at all
- [`tkt reorg backups`](/en/docs/reference/commands/maintenance.md#tkt-reorg-backups): List reorg backups, oldest first
- [`tkt reorg dismiss`](/en/docs/reference/commands/maintenance.md#tkt-reorg-dismiss): Never propose this again (stored in reviews/\_store.yaml); the last migration proposal dismissed raises the store's data level
- [`tkt reorg restore`](/en/docs/reference/commands/maintenance.md#tkt-reorg-restore): Put the store back to a reorg backup (every later change to tickets, groups, docs is lost)

## Related

- Error code · 409: [`ERR_REORG_CONTEXT_LOSS`](/en/docs/reference/errors.md#ERR_REORG_CONTEXT_LOSS): A reorg plan would lose a ticket's named or critical context
- Doctor · warning: [`STORE_OUTDATED`](/en/docs/reference/doctor.md#doctor-STORE_OUTDATED): The store's data is older than this tkt writes (schemaVersion): tkt reorg proposes the migration and raises it
