1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/db/migrate/20230323104259_migrate_chaining_system.rb
2023-03-24 10:16:21 +01:00

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