# `Tayori.Migrations`
[🔗](https://github.com/hattoriai/tayori/blob/v0.1.0/lib/tayori/migrations.ex#L1)

The tables of Tayori, in a migration of the app.

    $ mix tayori.gen.migration

writes a migration that pins the latest version:

    defmodule MyApp.Repo.Migrations.AddTayori do
      use Ecto.Migration

      def up, do: Tayori.Migrations.up(version: 1)
      def down, do: Tayori.Migrations.down(to: 0)
    end

The versions are `PhoenixMountable.Migrations`: tracked in the app's
database (per prefix), checked when the admin is first used, and run on
PostgreSQL and on SQLite. A later version of Tayori that changes the
tables has a version 2; `mix tayori.gen.migration` then writes the
migration that upgrades.

The tables (version 1):

  * `tayori_entries` - an entry of the news: its slug, categories, the
    segments of readers it is for, and when it is published (nil while it
    is a draft);
  * `tayori_translations` - the title, summary and body of an entry, one
    row for each language;
  * `tayori_reads` - for each reader, when they last saw the news;
  * `tayori_settings` - the settings of the admin, such as the AI model
    and its key, encrypted.

`up/1` takes `:version` and `:prefix` (the schema of the tables, in
PostgreSQL); `down/1` takes `:to` and `:prefix`.

# `check`

`:ok`, `{:pending, message}` or `{:outdated, message}`. Takes `:repo` and `:prefix`.

# `down`

Rolls the library's tables back to `:to` (default `0`). Call it from a host migration.

# `latest_version`

The latest version of the library's schema.

# `migrated_version`

The version the database is at (`0` when not installed).

# `run_backfills`

Runs deferred backfills to completion. Takes `:repo` and `:prefix`.

# `status`

The version, compatibility and backfills of a database. Takes `:repo` and `:prefix`.

# `up`

Migrates the library's tables up. Call it from a host migration.

# `verify`

Checks the tables against the library's schema. Takes `:repo` and `:prefix`.

---

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