@@ -85,10 +85,19 @@ defmodule Ecto.Migrator do
8585 repos: Application.fetch_env!(:my_app, :ecto_repos),
8686 skip: System.get_env("SKIP_MIGRATIONS") == "true"}
8787
88- To skip migrations you can also pass `skip: true` or as in the example
88+ To skip migrations you can also pass `skip: true` or as in the example
8989 set the environment variable `SKIP_MIGRATIONS` to a truthy value.
9090
91- To roll back you'd do it normally:
91+ And all other options described in `up/4` are allowed,
92+ for example if you want to log the SQL commands,
93+ and run migrations in a prefix:
94+
95+ {Ecto.Migrator,
96+ repos: Application.fetch_env!(:my_app, :ecto_repos),
97+ log_migrator_sql: true,
98+ prefix: "my_app"}
99+
100+ To roll back you'd do it normally:
92101
93102 $ mix ecto.rollback
94103
@@ -466,33 +475,37 @@ defmodule Ecto.Migrator do
466475 |> collect_migrations ( directories )
467476 |> Enum . sort_by ( fn { _ , version , _ } -> version end )
468477 end
469-
478+
470479 use GenServer
471480
472481 @ doc """
473482 Runs migrations as part of your supervision tree.
474483
475484 ## Options
476485
477- * `:repos` - Required option to tell the migrator which Repo's to
486+ * `:repos` - Required option to tell the migrator which Repo's to
478487 migrate. Example: `repos: [MyApp.Repo]`
479- * `:skip` - Option to skip migrations.
480- Defaults to `false`.
488+
489+ * `:skip` - Option to skip migrations. Defaults to `false`.
490+
491+ Plus all other options described in `up/4`.
492+
493+ See "Example: Running migrations on application startup" for more info.
481494 """
482495 def start_link ( opts ) do
483496 GenServer . start_link ( __MODULE__ , opts , name: __MODULE__ )
484497 end
485498
486499 @ impl true
487500 def init ( opts ) do
488- repos = Keyword . fetch !( opts , :repos )
489-
490- skip? = Keyword . get ( opts , :skip , false )
491- migrator = Keyword . get ( opts , :migrator , & Ecto.Migrator . run / 3 )
501+ { repos , opts } = Keyword . pop !( opts , :repos )
502+ { skip? , opts } = Keyword . pop ( opts , :skip , false )
503+ { migrator , opts } = Keyword . pop ( opts , :migrator , & Ecto.Migrator . run / 3 )
504+ opts = Keyword . put ( opts , :all , true )
492505
493506 unless skip? do
494507 for repo <- repos do
495- { :ok , _ , _ } = with_repo ( repo , & migrator . ( & 1 , :up , all: true ) )
508+ { :ok , _ , _ } = with_repo ( repo , & migrator . ( & 1 , :up , opts ) )
496509 end
497510 end
498511
0 commit comments