Skip to content

Commit 22334da

Browse files
authored
Further clarification to migration and execute/1 docs (#588) (#591)
1 parent e498963 commit 22334da

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

lib/ecto/migration.ex

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,16 @@ defmodule Ecto.Migration do
163163
164164
## Executing and flushing
165165
166-
Most functions in this module, when executed inside of migrations,
167-
are not executed immediately. Instead they are performed after the
168-
relevant `up`, `change`, or `down` callback terminates.
166+
Most functions in this module, when executed inside of migrations, are not
167+
executed immediately. Instead they are performed after the relevant `up`,
168+
`change`, or `down` callback terminates. Any other functions, such as
169+
functions provided by `Ecto.Repo`, will be executed immediately unless they
170+
are called from within an anonymous function passed to `execute/1`.
169171
170-
However, in some situations you may want to guarantee that all of the
171-
previous steps have been executed before continuing. This is useful when
172-
you need to apply a set of changes to the table before continuing with the
173-
migration. This can be done with `flush/0`:
172+
In some situations you may want to guarantee that all of the previous steps
173+
have been executed before continuing. This is useful when you need to apply a
174+
set of changes to the table before continuing with the migration. This can be
175+
done with `flush/0`:
174176
175177
def up do
176178
...
@@ -958,11 +960,15 @@ defmodule Ecto.Migration do
958960
Executes arbitrary SQL, anonymous function or a keyword command.
959961
960962
The argument is typically a string, containing the SQL command to be executed.
961-
Keyword commands exist for non-SQL adapters and are not used in most situations.
962-
963-
Supplying an anonymous function does allow for arbitrary code to execute as
964-
part of the migration. This is most often used in combination with `repo/0`
965-
by library authors who want to create high-level migration helpers.
963+
Keyword commands exist for non-SQL adapters and are not used in most
964+
situations.
965+
966+
You may instead run arbitrary code as part of your migration by supplying an
967+
anonymous function. This defers execution of the anonymous function until
968+
the migration callback has terminated (see [Executing and
969+
flushing](#module-executing-and-flushing)). This is most often used in
970+
combination with `repo/0` by library authors who want to create high-level
971+
migration helpers.
966972
967973
Reversible commands can be defined by calling `execute/2`.
968974

0 commit comments

Comments
 (0)