# `mix riddler.upgrade`
[🔗](https://github.com/riddler/riddler-ex/blob/v0.9.0/lib/mix/tasks/riddler.upgrade.ex#L1)

Rewrites the screen document in one file from version 1 to version 2.

    mix riddler.upgrade path/to/patron_registration.json

It makes exactly two changes, the ones `Riddler.Screens.upgrade/1` makes to
a decoded document: `schema_version` becomes `2`, written in where the
document declared none, and the `nodes` key of every screen and of every
`variant` becomes `elements`, its list as written. The file is edited in
place and every other byte of it - the other keys, their order, the
whitespace - is left as it was written. Nothing else in the document is
read or changed, so a document that is wrong stays wrong in the same way.

Admission never rewrites a document: a version 1 document is admitted as
version 1 until its host runs this task, or calls `Riddler.Screens.upgrade/1`
from its own migration, and nothing rewrites it but that.

## What it answers

A version 1 document is rewritten, and the task says so. A version 2
document is left as it is and nothing is written, so running the task twice
is running it once. The task exits 1, writing nothing, for a path that
cannot be read, a file that is not JSON, a document
`Riddler.Screens.Document.admit/1` answers `nil` for, a version 1 document
that already carries an `elements` key on a screen or an element, a
document whose `schema_version` is neither 1 nor 2, and a file whose edited
text would not decode to the document `Riddler.Screens.upgrade/1` answers;
the message names which. It takes one path and no options.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
