Skip to content

Commit

Permalink
Notify only projects not already notified
Browse files Browse the repository at this point in the history
Otherwise we get errors like this one:

    ActiveRecord::RecordInvalid: Validation failed: Notification These notification and project are already associated
    from /usr/lib64/ruby/gems/3.1.0/gems/activerecord-7.0.8/lib/active_record/validations.rb:80:in `raise_validation_error'
  • Loading branch information
danidoni committed Oct 5, 2023
1 parent c66dc31 commit fa4bec0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/api/db/data/20200421121610_backfill_notified_projects.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class BackfillNotifiedProjects < ActiveRecord::Migration[6.0]
def up
Notification.where.not(notifiable_id: nil).where.not(notifiable_type: nil).find_each do |notification|
notification.projects << NotifiedProjects.new(notification).call
projects_to_notify = NotifiedProjects.new(notification).call
already_notified = notification.projects
filtered_projects = projects_to_notify - already_notified
notification.projects << filtered_projects
rescue ActiveRecord::RecordNotUnique
# We don't have to do anything...
end
Expand Down

0 comments on commit fa4bec0

Please sign in to comment.