Ruby on Rails 6 Postgres upsert_all differentiate between updates and inserts

Viewed 215

I'm successfully updating some records using upsert_all, but now I'm working on a feature that should log the records that have been updated or created.

new_postcodes [{
  postcode: 'QBC123',
  created_at: Time.current,
  updated_at: Time.current,
}, {
  ...
}]

Postcode.upsert_all(new_postcodes, returning: ['postcode'], unique_by: :index_postcodes_on_postcode)

As far as I can tell upsert_all doesn't provide any details of what actually happened, and because I am also sending the updated_at date I can't differentiate between the records. Only idea I have would be to set a default value on the database field in Postgres, but I'd rather not do that.

0 Answers
Related