Fix CreateStockEvents migration for DBs without Delivery and/or StockTaking
This commit is contained in:
parent
c6250de945
commit
00bb10d14a
1 changed files with 3 additions and 1 deletions
|
@ -11,7 +11,9 @@ class CreateStockEvents < ActiveRecord::Migration[4.2]
|
||||||
dir.up do
|
dir.up do
|
||||||
change_column_default :stock_events, :type, nil
|
change_column_default :stock_events, :type, nil
|
||||||
|
|
||||||
diff = [StockEvent.maximum(:id) + 1 - StockTaking.minimum(:id), 0].max
|
stock_event_max = StockEvent.maximum(:id) || 0
|
||||||
|
stock_taking_min = StockTaking.minimum(:id) || 0
|
||||||
|
diff = [stock_event_max + 1 - stock_taking_min, 0].max
|
||||||
|
|
||||||
execute "UPDATE stock_changes SET stock_event_id = stock_taking_id + #{diff}
|
execute "UPDATE stock_changes SET stock_event_id = stock_taking_id + #{diff}
|
||||||
WHERE stock_taking_id IS NOT NULL"
|
WHERE stock_taking_id IS NOT NULL"
|
||||||
|
|
Loading…
Reference in a new issue