Ecto.Migration

Parsed documentation:
View on GitHub
Migrations are used to modify your database schema over time.

This module provides many helpers for migrating the database,
allowing developers to use Elixir to alter their storage in
a way that is database independent.

Here is an example:

    defmodule MyRepo.Migrations.CreatePosts do
      use Ecto.Migration

      def up do
        create table(:weather) do
          add :city,    :string, size: 40
          add :temp_lo, :integer
          add :temp_hi, :integer
          add :prcp,    :float

          timestamps
        end
      end

      def down do
        drop table(:weather)
      end
    end

Note migrations have an `up/0` and `down/0` instructions, where
`up/0` is used to update your database and `down/0` rolls back
the prompted changes.

Ecto provides some mix tasks to help developers work with migrations:

  * `mix ecto.gen.migration add_weather_table` - generates a
    migration that the user can fill in with particular commands
  * `mix ecto.migrate` - migrates a repository
  * `mix ecto.rollback` - rolls back a particular migration

Run the `mix help COMMAND` for more information.

## Change

Migrations can also be automatically reversible by implementing
`change/0` instead of `up/0` and `down/0`. For example, the
migration above can be written as:

    defmodule MyRepo.Migrations.CreatePosts do
      use Ecto.Migration

      def change do
        create table(:weather) do
          add :city,    :string, size: 40
          add :temp_lo, :integer
          add :temp_hi, :integer
          add :prcp,    :float

          timestamps
        end
      end
    end

Notice not all commands are reversible though. Trying to rollback
a non-reversible command will raise an `Ecto.MigrationError`.

## Transactions

By default, Ecto runs all migrations inside a transaction. That's not always
ideal: for example, PostgreSQL allows to create/drop indexes concurrently but
only outside of any transaction (see the [PostgreSQL
docs](http://www.postgresql.org/docs/9.2/static/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY)).

Migrations can be forced to run outside a transaction by setting the
`@disable_ddl_transaction` module attribute to `true`:

    defmodule MyRepo.Migrations.CreateIndexes do
      use Ecto.Migration
      @disable_ddl_transaction true

      def change do
        create index(:posts, [:slug], concurrently: true)
      end
    end

Since running migrations outside a transaction can be dangerous, consider
performing very few operations in such migrations.

See the `index/3` function for more information on creating/dropping indexes
concurrently.
No suggestions.
Please help! Open an issue on GitHub if this assessment is incorrect.