1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/db/migrate/20220720135828_migrate_slots_notifications.rb

23 lines
916 B
Ruby
Raw Normal View History

2022-07-20 16:20:09 +02:00
# frozen_string_literal: true
# We migrate existing notifications to be attached to a SlotsReservation instead of a Slot,
# because these notifications are now expecting a SlotsReservation
class MigrateSlotsNotifications < ActiveRecord::Migration[5.2]
def up
Notification.where(attached_object_type: 'Slot').each do |notification|
slot = notification.attached_object
slots_reservation = slot&.slots_reservations
&.includes(:reservation)
&.where('reservations.statistic_profile_id': notification.receiver.statistic_profile.id)
&.first
notification.update(attached_object: slots_reservation)
end
end
def down
Notification.where(attached_object_type: 'SlotsReservation').each do |notification|
notification.update(attached_object: notification.attached_object&.slot)
end
end
end