# `mix phoenix_mountable.gen.migration`
[🔗](https://github.com/hattoriai/phoenix_mountable/blob/v0.2.1/lib/mix/tasks/phoenix_mountable.gen.migration.ex#L2)

Generates the host migration that installs or upgrades a library's tables.

    $ mix phoenix_mountable.gen.migration MyLib.Migrations

The version the host is at is read from its existing migrations (the
highest `MyLib.Migrations.up(version: n)`), so it works before the
database is migrated. The new migration pins the latest version:

    def up, do: MyLib.Migrations.up(version: 4)
    def down, do: MyLib.Migrations.down(to: 2)

It adds `@disable_ddl_transaction` and `@disable_migration_lock` when a
version needs them, and notes contract changes, irreversible versions and
backfills as comments. The file is created by `mix ecto.gen.migration`,
so it follows the host's Ecto conventions.

Libraries usually wrap it in a task of their own:

    defmodule Mix.Tasks.MyLib.Gen.Migration do
      use Mix.Task
      @shortdoc "Generates the migration for MyLib"
      def run(args), do: Mix.Task.run("phoenix_mountable.gen.migration", ["MyLib.Migrations" | args])
    end

## Options

  * `-r`, `--repo` — the repo (defaults to the app's `:ecto_repos`)
  * `--to` — the version to migrate to. Defaults to the latest.
  * `--from` — the version the host is at, when it cannot be read from its
    migrations (an existing `up()` without a version). Without it, the
    database is asked.
  * `--migrations-path` — where to write the migration

---

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