Ecto SQL v3.0.0-rc.1 Ecto.Migrator View Source
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)
Link to this section Summary
Functions
Runs a down migration on the given repository
Gets all migrated versions
Returns an array of tuples as the migration status of the given repo, without actually running any migrations
Returns an array of tuples as the migration status of the given repo, without actually running any migrations
Gets the migrations path from a repository
Runs migrations for the given repository
Apply migrations to a repository with a given strategy
Runs an up migration on the given repository
Link to this section Functions
Runs a down migration on the given repository.
Options
:log
- the level to use for logging. Defaults to:info
. Can be any ofLogger.level/0
values or a boolean.:log_sql
- the level to use for logging of SQL instructions. Defaults tofalse
. Can be any ofLogger.level/0
values or a boolean.:prefix
- the prefix to run the migrations on
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
:prefix
- the prefix to run the migrations on
migrations(Ecto.Repo.t()) :: [ {:up | :down, id :: integer(), name :: String.t()} ]
Returns an array of tuples as the migration status of the given repo, without actually running any migrations.
Equivalent to:
Ecto.Migrator.migrations(repo, Ecto.Migrator.migrations_path(repo))
migrations(Ecto.Repo.t(), String.t()) :: [ {:up | :down, id :: integer(), name :: String.t()} ]
Returns an array of tuples as the migration status of the given repo, without actually running any migrations.
migrations_path(Ecto.Repo.t()) :: String.t()
Gets the migrations path from a repository.
run(Ecto.Repo.t(), atom(), Keyword.t()) :: [integer()]
Runs migrations for the given repository.
Equivalent to:
Ecto.Migrator.run(repo, Ecto.Migrator.migrations_path(repo), direction, opts)
Apply migrations to a repository with a given strategy.
The second argument identifies where the migrations are sourced from. A file path may be passed, in which case the migrations will be loaded from this during the migration process. The other option is to pass a list of tuples that identify the version number and migration modules to be run, for example:
Ecto.Migrator.run(Repo, [{0, MyApp.Migration1}, {1, MyApp.Migration2}, ...], :up, opts)
A strategy must be given as an option.
Options
:all
- runs all available iftrue
: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 ofLogger.level/0
values or a boolean.:prefix
- the prefix to run the migrations on
up(Ecto.Repo.t(), integer(), module(), Keyword.t()) :: :ok | :already_up
Runs an up migration on the given repository.
Options
:log
- the level to use for logging of migration instructions. Defaults to:info
. Can be any ofLogger.level/0
values or a boolean.:log_sql
- the level to use for logging of SQL instructions. Defaults tofalse
. Can be any ofLogger.level/0
values or a boolean.:prefix
- the prefix to run the migrations on:strict_version_order
- abort when applying a migration with old timestamp