1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/db/migrate/20230323104259_migrate_chaining_system.rb

23 lines
670 B
Ruby
Raw Normal View History

2023-03-23 17:39:06 +01:00
# 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