keephq / keep

The open-source alert management and AIOps platform
https://keephq.dev
Other
4.37k stars 442 forks source link

[🐛 Bug]: `deleted_at` default is wrong (at least for sqlite) and migration breaks incidents alerts #2302

Open shahargl opened 3 days ago

shahargl commented 3 days ago

some context -

  1. On the migration: server_default="1000-01-01 00:00:00",

  2. But on SQLite, this isn't the default:

    print(query.statement.compile(dialect=sqlite.dialect(), compile_kwargs={"literal_binds": True}))
    SELECT alert.timestamp, alert.event, alert.id, alert.tenant_id, alert.provider_type, alert.provider_id, alert.fingerprint, alert.alert_hash, alerttoincident.incident_id, alerttoincident.tenant_id AS tenant_id_1, alerttoincident.timestamp AS timestamp_1, alerttoincident.alert_id, alerttoincident.is_created_by_ai, alerttoincident.deleted_at 
    FROM alert JOIN alerttoincident ON alerttoincident.alert_id = alert.id JOIN incident ON alerttoincident.incident_id = incident.id 
    WHERE alerttoincident.tenant_id = 'keep' AND incident.id = 'bf430dddec1642e7b1c9327c79bbf2cd' AND alerttoincident.deleted_at = '1000-01-01 00:00:00.000000' ORDER BY alert.timestamp DESC
  3. Local workaround:

    UPDATE alerttoincident 
    SET deleted_at = '1000-01-01 00:00:00.000000' 
    WHERE deleted_at = '1000-01-0   ...> SET deleted_at = '1000-01-01 00:00:00.000000'