mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
23 lines
670 B
Ruby
23 lines
670 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
# From this migration, we migrate the chaining system to the new chained_elements table
|
||
|
class MigrateChainingSystem < ActiveRecord::Migration[6.1]
|
||
|
def up
|
||
|
[Invoice, InvoiceItem, HistoryValue, PaymentSchedule, PaymentScheduleItem, PaymentScheduleObject].each do |klass|
|
||
|
order = klass == HistoryValue ? :created_at : :id
|
||
|
previous = nil
|
||
|
klass.order(order).find_each do |item|
|
||
|
created = ChainedElement.create!(
|
||
|
element: item,
|
||
|
previous: previous
|
||
|
)
|
||
|
previous = created
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def down
|
||
|
execute("TRUNCATE TABLE #{ChainedElement.arel_table.name}")
|
||
|
end
|
||
|
end
|