LangEx.Migration (LangEx v0.11.3)

Copy Markdown View Source

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

Usage

Generate an Ecto migration that wraps calls to LangEx.Migration:

mix ecto.gen.migration add_lang_ex

Then in the generated migration:

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

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

Run mix ecto.migrate to create the tables.

Versioned Upgrades

Migrations between versions are idempotent. When upgrading LangEx, generate a new migration and specify the version:

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

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

Schema Isolation (Prefixes)

Supports PostgreSQL schema namespacing via the prefix option:

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

Summary

Functions

Returns the latest migration version.

Rolls back migrations down to the specified version (default: removes all).

Runs all migrations up to the specified version (default: latest).

Functions

current_version()

@spec current_version() :: pos_integer()

Returns the latest migration version.

down(opts \\ [])

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

Rolls back migrations down to the specified version (default: removes all).

Options

  • :version - target version to roll back to (default: 0, removes everything)
  • :prefix - PostgreSQL schema prefix (default: "public")

up(opts \\ [])

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

Runs all migrations up to the specified version (default: latest).

Options

  • :version - target migration version (default: 2)
  • :prefix - PostgreSQL schema prefix (default: "public")