@@ -376,7 +376,7 @@ defmodule Ecto.Migrator do
376376
377377 Ecto.Migrator.run(Repo, [{0, MyApp.Migration1}, {1, MyApp.Migration2}, ...], :up, opts)
378378
379- A strategy (which is one of `:all`, `:step` or `:to `) must be given as
379+ A strategy (which is one of `:all`, `:step`, `:to`, or `:to_exclusive `) must be given as
380380 an option.
381381
382382 ## Execution model
@@ -401,6 +401,9 @@ defmodule Ecto.Migrator do
401401 * `:to` - runs all until the supplied version is reached
402402 (including the version given in `:to`)
403403
404+ * `:to_exclusive` - runs all until the supplied version is reached
405+ (excluding the version given in `:to_exclusive`)
406+
404407 Plus all other options described in `up/4`.
405408 """
406409 @ spec run ( Ecto.Repo . t , String . t | [ String . t ] | [ { integer , module } ] , atom , Keyword . t ) :: [ integer ]
@@ -422,10 +425,12 @@ defmodule Ecto.Migrator do
422425 pending_all ( versions , migration_source , direction )
423426 to = opts [ :to ] ->
424427 pending_to ( versions , migration_source , direction , to )
428+ to_exclusive = opts [ :to_exclusive ] ->
429+ pending_to_exclusive ( versions , migration_source , direction , to_exclusive )
425430 step = opts [ :step ] ->
426431 pending_step ( versions , migration_source , direction , step )
427432 true ->
428- { :error , ArgumentError . exception ( "expected one of :all, :to, or :step strategies" ) }
433+ { :error , ArgumentError . exception ( "expected one of :all, :to, :to_exclusive, or :step strategies" ) }
429434 end
430435 end
431436
@@ -562,6 +567,18 @@ defmodule Ecto.Migrator do
562567 |> Enum . take_while ( & ( within_target_version? . ( & 1 , target , direction ) ) )
563568 end
564569
570+ defp pending_to_exclusive ( versions , migration_source , direction , target ) do
571+ within_target_version? = fn
572+ { version , _ , _ } , target , :up ->
573+ version < target
574+ { version , _ , _ } , target , :down ->
575+ version > target
576+ end
577+
578+ pending_in_direction ( versions , migration_source , direction )
579+ |> Enum . take_while ( & ( within_target_version? . ( & 1 , target , direction ) ) )
580+ end
581+
565582 defp pending_step ( versions , migration_source , direction , count ) do
566583 pending_in_direction ( versions , migration_source , direction )
567584 |> Enum . take ( count )
0 commit comments