Ecto.Migrator

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)

Summary

Functions

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

Runs a down migration on the given repository

migrated_versions(repo, opts \\ [])

Gets all migrated versions

migrations(repo, directory)

Returns an array of tuples as the migration status of the given repo, without actually running any migrations

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.

migrated_versions(repo, opts \\ [])

migrated_versions(Ecto.Repo.t, Keyword.t) :: [integer]

Gets all migrated versions.

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

Options

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

migrations(repo, directory)

Returns an array of tuples as the migration status of the given repo, without actually running any migrations.

run(repo, directory, direction, opts)

run(Ecto.Repo.t, binary, atom, Keyword.t) :: [integer]

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.

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

up(Ecto.Repo.t, integer, module, Keyword.t) ::
  :ok |
  :already_up |
  no_return

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.
  • :prefix - the prefix to run the migrations on

© 2012 Plataformatec
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/ecto/Ecto.Migrator.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部