-- Which alert source an alert last arrived on. -- -- Team -> Sources shows when each source last posted, which integrations -- already knew (last_used_at, stamped on every webhook). What it could not say -- was what a source delivered: an alert never recorded the key it came in on, so -- "prod alertmanager" and "staging alertmanager" were indistinguishable once -- inside. This column is that link, and lets the page show each source's last -- alert and how many alerts it has kept fresh over the past day. -- -- Last sender wins: every accepted payload restamps it, the way it advances -- received_at. Two sources posting the same fingerprint into one team is -- already one alert, and it is attributed to whichever spoke last. -- -- Nullable, and not backfilled. Alerts that arrived before this migration have -- no source, and NULL says so honestly rather than guessing. It heals by itself: -- Alertmanager re-sends every alert each repeat_interval, and each re-send is an -- accepted payload. Deleting a source keeps its alerts, unattributed. ALTER TABLE alerts ADD COLUMN integration_id BIGINT REFERENCES integrations(id) ON DELETE SET NULL; CREATE INDEX alerts_integration_idx ON alerts (integration_id, received_at) WHERE integration_id IS NOT NULL;