@@ -3,9 +3,10 @@ defmodule Ecto.MigrationTest do
3
3
# is global state, we can run it async as long as this is
4
4
# the only test case that uses the Runner in async mode.
5
5
use ExUnit.Case , async: true
6
-
7
6
use Ecto.Migration
8
7
8
+ import Support.FileHelpers
9
+
9
10
alias EctoSQL.TestRepo
10
11
alias Ecto.Migration . { Table , Index , Reference , Constraint }
11
12
alias Ecto.Migration.Runner
@@ -694,6 +695,16 @@ defmodule Ecto.MigrationTest do
694
695
assert "SELECT 1" = last_command ( )
695
696
end
696
697
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
+
697
708
test "fails gracefully with nested create" do
698
709
assert_raise Ecto.MigrationError , "cannot execute nested commands" , fn ->
699
710
create table ( :posts ) do
@@ -857,5 +868,19 @@ defmodule Ecto.MigrationTest do
857
868
assert "SELECT 2" = last_command ( )
858
869
end
859
870
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
+
860
885
defp last_command ( ) , do: Process . get ( :last_command )
861
886
end
0 commit comments