@@ -217,18 +217,18 @@ defmodule Ecto.Migration.Runner do
217217 end
218218
219219 defp reverse ( { :create , % Index { } = index } ) ,
220- do: { :drop , index }
220+ do: { :drop , index , nil }
221221 defp reverse ( { :create_if_not_exists , % Index { } = index } ) ,
222- do: { :drop_if_exists , index }
223- defp reverse ( { :drop , % Index { } = index } ) ,
222+ do: { :drop_if_exists , index , nil }
223+ defp reverse ( { :drop , % Index { } = index , _ } ) ,
224224 do: { :create , index }
225- defp reverse ( { :drop_if_exists , % Index { } = index } ) ,
225+ 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 }
229+ do: { :drop , table , nil }
230230 defp reverse ( { :create_if_not_exists , % Table { } = table , _columns } ) ,
231- do: { :drop_if_exists , table }
231+ do: { :drop_if_exists , table , nil }
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 }
245+ do: { :drop_if_exists , constraint , nil }
246246 defp reverse ( { :create , % Constraint { } = constraint } ) ,
247- do: { :drop , constraint }
247+ do: { :drop , constraint , nil }
248248
249249 defp reverse ( _command ) , do: false
250250
@@ -361,18 +361,26 @@ 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 } ) ,
364+ defp command ( { :drop , % Table { } = table , :cascade } ) ,
365+ do: command ( { :drop , table , nil } ) <> " cascade"
366+ defp command ( { :drop , % Table { } = table , _ } ) ,
365367 do: "drop table #{ quote_name ( table . prefix , table . name ) } "
366- defp command ( { :drop_if_exists , % Table { } = table } ) ,
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 , _ } ) ,
367371 do: "drop table if exists #{ quote_name ( table . prefix , table . name ) } "
368372
369373 defp command ( { :create , % Index { } = index } ) ,
370374 do: "create index #{ quote_name ( index . prefix , index . name ) } "
371375 defp command ( { :create_if_not_exists , % Index { } = index } ) ,
372376 do: "create index if not exists #{ quote_name ( index . prefix , index . name ) } "
373- defp command ( { :drop , % Index { } = index } ) ,
377+ defp command ( { :drop , % Index { } = index , :cascade } ) ,
378+ do: command ( { :drop , index , nil } ) <> " cascade"
379+ defp command ( { :drop , % Index { } = index , _ } ) ,
374380 do: "drop index #{ quote_name ( index . prefix , index . name ) } "
375- defp command ( { :drop_if_exists , % Index { } = index } ) ,
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 , _ } ) ,
376384 do: "drop index if exists #{ quote_name ( index . prefix , index . name ) } "
377385 defp command ( { :rename , % Table { } = current_table , % Table { } = new_table } ) ,
378386 do: "rename table #{ quote_name ( current_table . prefix , current_table . name ) } to #{ quote_name ( new_table . prefix , new_table . name ) } "
@@ -387,9 +395,9 @@ defmodule Ecto.Migration.Runner do
387395 do: "create check constraint #{ constraint . name } on table #{ quote_name ( constraint . prefix , constraint . table ) } "
388396 defp command ( { :create , % Constraint { exclude: exclude } = constraint } ) when is_binary ( exclude ) ,
389397 do: "create exclude constraint #{ constraint . name } on table #{ quote_name ( constraint . prefix , constraint . table ) } "
390- defp command ( { :drop , % Constraint { } = constraint } ) ,
398+ defp command ( { :drop , % Constraint { } = constraint , _ } ) ,
391399 do: "drop constraint #{ constraint . name } from table #{ quote_name ( constraint . prefix , constraint . table ) } "
392- defp command ( { :drop_if_exists , % Constraint { } = constraint } ) ,
400+ defp command ( { :drop_if_exists , % Constraint { } = constraint , _ } ) ,
393401 do: "drop constraint if exists #{ constraint . name } from table #{ quote_name ( constraint . prefix , constraint . table ) } "
394402
395403 defp quote_name ( nil , name ) , do: quote_name ( name )
0 commit comments