@@ -217,18 +217,18 @@ defmodule Ecto.Migration.Runner do
217217 end
218218
219219 defp reverse ( { :create , % Index { } = index } ) ,
220- do: { :drop , index , nil }
220+ do: { :drop , index , :restrict }
221221 defp reverse ( { :create_if_not_exists , % Index { } = index } ) ,
222- do: { :drop_if_exists , index , nil }
222+ do: { :drop_if_exists , index , :restrict }
223223 defp reverse ( { :drop , % Index { } = index , _ } ) ,
224224 do: { :create , index }
225225 defp reverse ( { :drop_if_exists , % Index { } = index , _ } ) ,
226226 do: { :create_if_not_exists , index }
227227
228228 defp reverse ( { :create , % Table { } = table , _columns } ) ,
229- do: { :drop , table , nil }
229+ do: { :drop , table , :restrict }
230230 defp reverse ( { :create_if_not_exists , % Table { } = table , _columns } ) ,
231- do: { :drop_if_exists , table , nil }
231+ do: { :drop_if_exists , table , :restrict }
232232 defp reverse ( { :rename , % Table { } = table_current , % Table { } = table_new } ) ,
233233 do: { :rename , table_new , table_current }
234234 defp reverse ( { :rename , % Table { } = table , current_column , new_column } ) ,
@@ -242,9 +242,9 @@ defmodule Ecto.Migration.Runner do
242242 # It is not a good idea to reverse constraints because
243243 # we can't guarantee data integrity when applying them back.
244244 defp reverse ( { :create_if_not_exists , % Constraint { } = constraint } ) ,
245- do: { :drop_if_exists , constraint , nil }
245+ do: { :drop_if_exists , constraint , :restrict }
246246 defp reverse ( { :create , % Constraint { } = constraint } ) ,
247- do: { :drop , constraint , nil }
247+ do: { :drop , constraint , :restrict }
248248
249249 defp reverse ( _command ) , do: false
250250
@@ -361,27 +361,19 @@ defmodule Ecto.Migration.Runner do
361361 do: "create table if not exists #{ quote_name ( table . prefix , table . name ) } "
362362 defp command ( { :alter , % Table { } = table , _ } ) ,
363363 do: "alter table #{ quote_name ( table . prefix , table . name ) } "
364- defp command ( { :drop , % Table { } = table , :cascade } ) ,
365- do: command ( { :drop , table , nil } ) <> " cascade"
366- defp command ( { :drop , % Table { } = table , _ } ) ,
367- do: "drop table #{ quote_name ( table . prefix , table . name ) } "
368- defp command ( { :drop_if_exists , % Table { } = table , :cascade } ) ,
369- do: command ( { :drop_if_exists , table , nil } ) <> " cascade"
370- defp command ( { :drop_if_exists , % Table { } = table , _ } ) ,
371- do: "drop table if exists #{ quote_name ( table . prefix , table . name ) } "
364+ defp command ( { :drop , % Table { } = table , mode } ) ,
365+ do: "drop table #{ quote_name ( table . prefix , table . name ) } #{ drop_mode ( mode ) } "
366+ defp command ( { :drop_if_exists , % Table { } = table , mode } ) ,
367+ do: "drop table if exists #{ quote_name ( table . prefix , table . name ) } #{ drop_mode ( mode ) } "
372368
373369 defp command ( { :create , % Index { } = index } ) ,
374370 do: "create index #{ quote_name ( index . prefix , index . name ) } "
375371 defp command ( { :create_if_not_exists , % Index { } = index } ) ,
376372 do: "create index if not exists #{ quote_name ( index . prefix , index . name ) } "
377- defp command ( { :drop , % Index { } = index , :cascade } ) ,
378- do: command ( { :drop , index , nil } ) <> " cascade"
379- defp command ( { :drop , % Index { } = index , _ } ) ,
380- do: "drop index #{ quote_name ( index . prefix , index . name ) } "
381- defp command ( { :drop_if_exists , % Index { } = index , :cascade } ) ,
382- do: command ( { :drop_if_exists , index , nil } ) <> " cascade"
383- defp command ( { :drop_if_exists , % Index { } = index , _ } ) ,
384- do: "drop index if exists #{ quote_name ( index . prefix , index . name ) } "
373+ defp command ( { :drop , % Index { } = index , mode } ) ,
374+ do: "drop index #{ quote_name ( index . prefix , index . name ) } #{ drop_mode ( mode ) } "
375+ defp command ( { :drop_if_exists , % Index { } = index , mode } ) ,
376+ do: "drop index if exists #{ quote_name ( index . prefix , index . name ) } #{ drop_mode ( mode ) } "
385377 defp command ( { :rename , % Table { } = current_table , % Table { } = new_table } ) ,
386378 do: "rename table #{ quote_name ( current_table . prefix , current_table . name ) } to #{ quote_name ( new_table . prefix , new_table . name ) } "
387379 defp command ( { :rename , % Table { } = table , current_column , new_column } ) ,
@@ -400,6 +392,9 @@ defmodule Ecto.Migration.Runner do
400392 defp command ( { :drop_if_exists , % Constraint { } = constraint , _ } ) ,
401393 do: "drop constraint if exists #{ constraint . name } from table #{ quote_name ( constraint . prefix , constraint . table ) } "
402394
395+ defp drop_mode ( :restrict ) , do: ""
396+ defp drop_mode ( :cascade ) , do: " cascade"
397+
403398 defp quote_name ( nil , name ) , do: quote_name ( name )
404399 defp quote_name ( prefix , name ) , do: quote_name ( prefix ) <> "." <> quote_name ( name )
405400 defp quote_name ( name ) when is_atom ( name ) , do: quote_name ( Atom . to_string ( name ) )
0 commit comments