Ecto.Migrator

This module provides the migration API.

Example

defmodule MyApp.MigrationExample do
  use Ecto.Migration

  def up do
    execute "CREATE TABLE users(id serial PRIMARY_KEY, username text)"
  end

  def down do
    execute "DROP TABLE users"
  end
end

Ecto.Migrator.up(Repo, 20080906120000, MyApp.MigrationExample)
Source

Summary

down(repo, version, module, opts \\ [])

Runs a down migration on the given repository

migrated_versions(repo)

Gets all migrated versions

run(repo, directory, direction, opts)

Apply migrations in a directory to a repository with given strategy

up(repo, version, module, opts \\ [])

Runs an up migration on the given repository

Functions

down(repo, version, module, opts \\ [])

Runs a down migration on the given repository.

Options

  • :log - the level to use for logging. Defaults to :info. Can be any of Logger.level/0 values or false.
Source
migrated_versions(repo)

Specs:

Gets all migrated versions.

This function ensures the migration table exists if no table has been defined yet.

Source
run(repo, directory, direction, opts)

Specs:

Apply migrations in a directory to a repository with given strategy.

A strategy must be given as an option.

Options

  • :all - runs all available if true
  • :step - runs the specific number of migrations
  • :to - runs all until the supplied version is reached
  • :log - the level to use for logging. Defaults to :info. Can be any of Logger.level/0 values or false.
Source
up(repo, version, module, opts \\ [])

Specs:

Runs an up migration on the given repository.

Options

  • :log - the level to use for logging. Defaults to :info. Can be any of Logger.level/0 values or false.
Source