Disclosure: The draft and sample SQL were generated with AI.
A calendar lists “Daily Turbo” at 18:00. An hour later the provider shifts it to 18:20. If your key is (title, start_time), the update looks like a new event. If you drop the time from the key, tomorrow’s “Daily Turbo” may overwrite today’s.
A reliable identifier is the provider’s occurrence ID, scoped to the namespace where it is unique. A recurring-series ID identifies a template, not one running of the tournament. If the provider has no reliable occurrence ID, don’t silently pretend a name and a clock time can supply one.
Use a separate revision to decide whether an update is newer. Receipt time tells you when you saw a message, not whether it supersedes another one. If the provider documents a monotonically increasing revision per occurrence, an upsert can enforce that ordering:
INSERT INTO event_occurrence
(source_namespace, source_occurrence_id, revision, title, starts_at, state)
VALUES
($1, $2, $3, $4, $5, $6)
ON CONFLICT (source_namespace, source_occurrence_id)
DO UPDATE SET
revision = EXCLUDED.revision,
title = EXCLUDED.title,
starts_at = EXCLUDED.starts_at,
state = EXCLUDED.state
WHERE EXCLUDED.revision > event_occurrence.revision;
Import revision 12 twice and you still have one row. Import revision 11 after 12 and a reschedule cannot roll back. If revision 13 cancels the event, retain that cancellation state instead of deleting the row: otherwise, a late revision 12 could insert the event again. If two messages carry the same revision but different content, flag the conflict.
A public calendar and a live lobby may use different IDs for the same occurrence. Store both identities and map them to a canonical listing only when you have an explicit cross-reference or have verified the match. A normalized title and a narrow time window can suggest a candidate, but shouldn’t merge it automatically.
Test a duplicate, a late older revision, a moved start time, two distinct events with the same title and time, and a cancellation followed by a retry. Also check that a partial page doesn’t cancel an event simply by omitting it.
I develop the 3BetLab tournament finder, where tournament cards link back to published sources. The SQL illustrates an ingestion pattern, not the production schema.