# `Countersign.Migrations`
[🔗](https://github.com/mkreyman/countersign/blob/v0.1.0/lib/countersign/migrations.ex#L1)

Creates and drops Countersign's tables from a host migration, in the
shape of `Oban.Migration`.

Generate the host migration with `mix countersign.gen.migration`, or write
it by hand:

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

      def up, do: Countersign.Migrations.up(version: 1)
      def down, do: Countersign.Migrations.down(version: 1)
    end

A later package release that changes the tables adds a version; the host
then adds a migration calling `up(version: 2)` and `down(version: 2)`.

## Versions

  1. `signing_requests` and `signing_codes`.
  2. `signing_requests.resent_times`, `verified_times` and `sign_method`:
     the time of every resend and every code verification, and whether
     the signature was drawn or typed, for the signing certificate
     (`Countersign.Certificate`).

## Options

  * `:version` - for `up/1`, the version to migrate up to (default: the
    current version, 2); for `down/1`, the version to migrate down to
    and including (default: 1, which drops every table).
  * `:prefix` - the Postgres schema to create the tables in (default
    `"public"`). A prefix other than `"public"` is created when missing
    and is never dropped.

Every statement is idempotent: running `up/1` or `down/1` twice, or again
after it stopped part-way, succeeds and leaves the same schema.

# `current_version`

```elixir
@spec current_version() :: pos_integer()
```

The newest migration version this release of Countersign ships.

# `down`

```elixir
@spec down(keyword()) :: :ok
```

Migrates down to and including `:version` (default 1). Call it inside a migration.

# `up`

```elixir
@spec up(keyword()) :: :ok
```

Migrates up to `:version` (default: the current version). Call it inside a migration.

---

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