# `HephaestusOban.Migration`
[🔗](https://github.com/lucas-stellet/hephaestus_oban/blob/v0.5.0/lib/hephaestus_oban/migration.ex#L1)

Migrations create and modify the database tables HephaestusOban needs to function.

## Usage

To use migrations in your application you'll need to generate an `Ecto.Migration` that wraps
calls to `HephaestusOban.Migration`:

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

      def up, do: HephaestusOban.Migration.up()
      def down, do: HephaestusOban.Migration.down()
    end

## Isolation with Prefixes

HephaestusOban supports namespacing through PostgreSQL schemas (prefixes):

    def up, do: HephaestusOban.Migration.up(prefix: "private")
    def down, do: HephaestusOban.Migration.down(prefix: "private")

## Versioning

Migrations are versioned and tracked via PostgreSQL table comments. Running `up/1`
will only apply migrations that haven't been run yet.

New installs can run all known versions:

    def up, do: HephaestusOban.Migration.up()
    def down, do: HephaestusOban.Migration.down()

Existing installs can upgrade incrementally to a specific version:

    def up, do: HephaestusOban.Migration.up(version: 3)
    def down, do: HephaestusOban.Migration.down(version: 2)

Use `migrated_version/1` to inspect the recorded version:

    HephaestusOban.Migration.migrated_version()
    HephaestusOban.Migration.migrated_version(prefix: "private")

# `down`

Run the `down` changes from the current version to the target version.

## Options

  * `:version` — target version to migrate down to (defaults to initial)
  * `:prefix` — PostgreSQL schema prefix (defaults to `"public"`)

For example, `down(version: 2)` removes V03 changes while keeping V01 and V02 applied.

# `migrated_version`

Check the latest version the database is migrated to.

## Options

  * `:prefix` — PostgreSQL schema prefix (defaults to `"public"`)

# `up`

Run the `up` changes for all migrations between the initial version and the current version.

## Options

  * `:version` — target version (defaults to latest)
  * `:prefix` — PostgreSQL schema prefix (defaults to `"public"`)

Versions are cumulative. For example, `up(version: 3)` runs V01, V02, and V03
on a fresh install, or only the missing migrations on an existing install.

---

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