Imison.Migration behaviour (Imison v0.1.0)

Copy Markdown View Source

Creates and upgrades Imison's tables in the host's database, one version at a time.

The host app wraps it in an Ecto migration of its own:

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

  def up, do: Imison.Migration.up(version: 1)
  def down, do: Imison.Migration.down(version: 1)
end

up() without a version migrates to the latest version. Versions already applied are skipped, so running a version twice changes nothing. When a release ships a new version, the host adds one more migration:

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

down(version: n) rolls back every applied version down to and including n; down() removes all of Imison's tables.

Prefixes

The tables go in the public schema unless prefix: names another, which is created when missing:

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

Summary

Callbacks

Migrates Imison's tables down to and including :version (default: the first).

Returns the version Imison's tables are migrated to, 0 when they don't exist.

Migrates Imison's tables up to :version (default: the latest).

Functions

Rolls back every applied version down to and including :version (default: the first).

Returns the version Imison's tables are migrated to, 0 when they don't exist.

Applies every version not yet applied, up to :version (default: the latest).

Callbacks

down(keyword)

@callback down(keyword()) :: :ok

Migrates Imison's tables down to and including :version (default: the first).

migrated_version(keyword)

@callback migrated_version(keyword()) :: non_neg_integer()

Returns the version Imison's tables are migrated to, 0 when they don't exist.

up(keyword)

@callback up(keyword()) :: :ok

Migrates Imison's tables up to :version (default: the latest).

Functions

down(opts \\ [])

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

Rolls back every applied version down to and including :version (default: the first).

Imison.Migration.down()
Imison.Migration.down(version: 2)
Imison.Migration.down(prefix: "private")

migrated_version(opts \\ [])

@spec migrated_version(keyword()) :: non_neg_integer()

Returns the version Imison's tables are migrated to, 0 when they don't exist.

Outside a migration, pass the repo:

Imison.Migration.migrated_version(repo: MyApp.Repo)

up(opts \\ [])

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

Applies every version not yet applied, up to :version (default: the latest).

Imison.Migration.up()
Imison.Migration.up(version: 1)
Imison.Migration.up(prefix: "private")