code: def dedup_alert(self, alert, history):
          
          alert.history = history
          update = """
              UPDATE alerts
                 SET status=%(status)s, service=%(service)s, value=%(value)s, text=%(text)s,
                     timeout=%(timeout)s, raw_data=%(raw_data)s, repeat=%(repeat)s,
                     last_receive_id=%(last_receive_id)s, last_receive_time=%(last_receive_time)s,
                     tags=ARRAY(SELECT DISTINCT UNNEST(tags || %(tags)s)), attributes=attributes || %(attributes)s,
                     duplicate_count=duplicate_count + 1, {update_time}, history=(%(history)s || history)[1:{limit}]
               WHERE environment=%(environment)s
                 AND resource=%(resource)s
                 AND event=%(event)s
                 AND severity=%(severity)s
                 AND {customer}
           RETURNING *
          """.format(
              limit=current_app.config['HISTORY_LIMIT'],
              update_time='update_time=%(update_time)s' if alert.update_time else 'update_time=update_time',
              customer='customer=%(customer)s' if alert.customer else 'customer IS NULL'
          )
          return self._updateone(update, vars(alert), returning=True)
docs: Update alert status, service, value, text, timeout and rawData, increment duplicate count and set
          repeat=True, and keep track of last receive id and time but don't append to history unless status changes.