# `StatifierPersistence.Ecto.Migrations.V08`
[🔗](https://github.com/riddler/statifier_persistence/blob/v0.18.0/lib/statifier_persistence/ecto/migrations/v08.ex#L2)

V08 of the package DDL: when an execution ended.

Two changes, one version:

- `ended_at`, a nullable `utc_datetime_usec` on `executions`, the
  type V07 gives `retired_at` on `charts`;
- a non-unique index on `executions(ended_at)`.

`ended_at` is written once, by the first terminal write a row takes
while the column is `NULL`, and never again:
`c:StatifierPersistence.Storage.Adapter.update_execution/2` keeps a
stored stamp over whatever the record it is given carries.
Before this version the only time an executions row carried was
`updated_at`, which any later write moves, so "how long has this
execution been finished" had no column that answered it and kept
answering it. The index is what a query over that column needs to
avoid a sequential scan of the whole executions table.

Every row that exists when this version runs gets a `NULL`, terminal
rows included: the version adds a column and backfills nothing, because
the time a row that is already terminal ended is not stored anywhere
to copy from. Such a row made its transition into a terminal status
before the column existed, so it reads `NULL` until a later terminal
write reaches it - a re-delivered settlement recording a child's
answer is one - and stamps it with that write's time.

Both changes are ones every backend has, so nothing here is guarded
by adapter, and the version runs inside an ordinary transaction.
`down/1` drops the index and the column, stamps and all.

# `down`

```elixir
@spec down(StatifierPersistence.Ecto.Config.t()) :: :ok
```

Drops the `executions(ended_at)` index and the column.

# `up`

```elixir
@spec up(StatifierPersistence.Ecto.Config.t()) :: :ok
```

Adds `ended_at` to `executions` and indexes it, per `config`.

---

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