models: double-write to the newly created foreign keys

This code is only used to handle a live system creating new
Administrateurs, Instructeurs or Experts before the migration to the new
foreign keys.
This commit is contained in:
Pierre de La Morinerie 2022-03-08 17:12:01 +00:00
parent d2f12e5188
commit ae3e360139

View file

@ -65,6 +65,21 @@ class User < ApplicationRecord
validate :does_not_merge_on_self, if: :requested_merge_into_id_changed?
# Temporary code for double writing the admin, instructeur and expert id to the foreign key
after_save do
if saved_change_to_attribute?(:administrateur_id) && administrateur_id.present?
Administrateur.find(administrateur_id).update!(user_id: id)
end
if saved_change_to_attribute?(:instructeur_id) && instructeur_id.present?
Instructeur.find(instructeur_id).update!(user_id: id)
end
if saved_change_to_attribute?(:expert_id) && expert_id.present?
Expert.find(expert_id).update!(user_id: id)
end
end
def validate_password_complexity?
administrateur?
end