@@ -3,9 +3,10 @@ defmodule Ecto.MigrationTest do
33 # is global state, we can run it async as long as this is
44 # the only test case that uses the Runner in async mode.
55 use ExUnit.Case , async: true
6-
76 use Ecto.Migration
87
8+ import Support.FileHelpers
9+
910 alias EctoSQL.TestRepo
1011 alias Ecto.Migration . { Table , Index , Reference , Constraint }
1112 alias Ecto.Migration.Runner
@@ -694,6 +695,16 @@ defmodule Ecto.MigrationTest do
694695 assert "SELECT 1" = last_command ( )
695696 end
696697
698+ test "forward: executes a command from a file" do
699+ in_tmp fn _path ->
700+ up_sql = ~s( CREATE TABLE IF NOT EXISTS "execute_file_table" \( i integer\) )
701+ File . write! ( "up.sql" , up_sql )
702+ execute_file "up.sql"
703+ flush ( )
704+ assert up_sql == last_command ( )
705+ end
706+ end
707+
697708 test "fails gracefully with nested create" do
698709 assert_raise Ecto.MigrationError , "cannot execute nested commands" , fn ->
699710 create table ( :posts ) do
@@ -857,5 +868,19 @@ defmodule Ecto.MigrationTest do
857868 assert "SELECT 2" = last_command ( )
858869 end
859870
871+ test "backward: reverses a command from a file" do
872+ in_tmp fn _path ->
873+ up_sql = ~s( CREATE TABLE IF NOT EXISTS "execute_file_table" \( i integer\) )
874+ File . write! ( "up.sql" , up_sql )
875+
876+ down_sql = ~s( DROP TABLE IF EXISTS "execute_file_table")
877+ File . write! ( "down.sql" , down_sql )
878+
879+ execute_file "up.sql" , "down.sql"
880+ flush ( )
881+ assert down_sql == last_command ( )
882+ end
883+ end
884+
860885 defp last_command ( ) , do: Process . get ( :last_command )
861886end
0 commit comments