@@ -217,18 +217,18 @@ defmodule Ecto.Migration.Runner do
217
217
end
218
218
219
219
defp reverse ( { :create , % Index { } = index } ) ,
220
- do: { :drop , index , nil }
220
+ do: { :drop , index , :restrict }
221
221
defp reverse ( { :create_if_not_exists , % Index { } = index } ) ,
222
- do: { :drop_if_exists , index , nil }
222
+ do: { :drop_if_exists , index , :restrict }
223
223
defp reverse ( { :drop , % Index { } = index , _ } ) ,
224
224
do: { :create , index }
225
225
defp reverse ( { :drop_if_exists , % Index { } = index , _ } ) ,
226
226
do: { :create_if_not_exists , index }
227
227
228
228
defp reverse ( { :create , % Table { } = table , _columns } ) ,
229
- do: { :drop , table , nil }
229
+ do: { :drop , table , :restrict }
230
230
defp reverse ( { :create_if_not_exists , % Table { } = table , _columns } ) ,
231
- do: { :drop_if_exists , table , nil }
231
+ do: { :drop_if_exists , table , :restrict }
232
232
defp reverse ( { :rename , % Table { } = table_current , % Table { } = table_new } ) ,
233
233
do: { :rename , table_new , table_current }
234
234
defp reverse ( { :rename , % Table { } = table , current_column , new_column } ) ,
@@ -242,9 +242,9 @@ defmodule Ecto.Migration.Runner do
242
242
# It is not a good idea to reverse constraints because
243
243
# we can't guarantee data integrity when applying them back.
244
244
defp reverse ( { :create_if_not_exists , % Constraint { } = constraint } ) ,
245
- do: { :drop_if_exists , constraint , nil }
245
+ do: { :drop_if_exists , constraint , :restrict }
246
246
defp reverse ( { :create , % Constraint { } = constraint } ) ,
247
- do: { :drop , constraint , nil }
247
+ do: { :drop , constraint , :restrict }
248
248
249
249
defp reverse ( _command ) , do: false
250
250
@@ -361,27 +361,19 @@ defmodule Ecto.Migration.Runner do
361
361
do: "create table if not exists #{ quote_name ( table . prefix , table . name ) } "
362
362
defp command ( { :alter , % Table { } = table , _ } ) ,
363
363
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 ) } "
372
368
373
369
defp command ( { :create , % Index { } = index } ) ,
374
370
do: "create index #{ quote_name ( index . prefix , index . name ) } "
375
371
defp command ( { :create_if_not_exists , % Index { } = index } ) ,
376
372
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 ) } "
385
377
defp command ( { :rename , % Table { } = current_table , % Table { } = new_table } ) ,
386
378
do: "rename table #{ quote_name ( current_table . prefix , current_table . name ) } to #{ quote_name ( new_table . prefix , new_table . name ) } "
387
379
defp command ( { :rename , % Table { } = table , current_column , new_column } ) ,
@@ -400,6 +392,9 @@ defmodule Ecto.Migration.Runner do
400
392
defp command ( { :drop_if_exists , % Constraint { } = constraint , _ } ) ,
401
393
do: "drop constraint if exists #{ constraint . name } from table #{ quote_name ( constraint . prefix , constraint . table ) } "
402
394
395
+ defp drop_mode ( :restrict ) , do: ""
396
+ defp drop_mode ( :cascade ) , do: " cascade"
397
+
403
398
defp quote_name ( nil , name ) , do: quote_name ( name )
404
399
defp quote_name ( prefix , name ) , do: quote_name ( prefix ) <> "." <> quote_name ( name )
405
400
defp quote_name ( name ) when is_atom ( name ) , do: quote_name ( Atom . to_string ( name ) )
0 commit comments