BACK_TO_COURSE
Track It Before Anyone Asks
Store It So You Can Change Your Mind
Keep the Original
You will define something wrong. If you only kept totals, you're stuck. If you kept the records, you fix the formula and run it again over all of history.
CREATE TABLE calls (
call_id TEXT PRIMARY KEY, -- the vendor's ID
started_at TEXT NOT NULL, -- always UTC
direction TEXT NOT NULL,
result TEXT NOT NULL, -- answered, missed, voicemail
talk_seconds INTEGER NOT NULL,
raw_json TEXT NOT NULL, -- what the API sent
fetched_at TEXT NOT NULL -- when we got it
);
And saving a record looks like this:
INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (call_id) DO UPDATE SET
started_at = excluded.started_at,
direction = excluded.direction,
result = excluded.result,
talk_seconds = excluded.talk_seconds,
raw_json = excluded.raw_json,
fetched_at = excluded.fetched_at;
In plain words: new call, add it. Seen it before, update it. That's what makes it safe to run twice.
Three Rules
- Save time in UTC, report in local time. 11:00 PM on November 29 in New York is 4:00 AM on November 30 in UTC. Group by the UTC date and late calls land on the wrong day. Use a named time zone like
America/New_York, not a fixed offset, because daylight saving moves twice a year. - Look back every time. Records change after the fact: a call gets a recording, or a result gets corrected. Re-pull the last few days each run. Upserts make that free.
- Watch for silence. Alert when no successful run has finished lately. A collector that dies quietly costs you history you can't get back.
TIP
Have AI write the freshness check along with the collector: "Alert me if the last successful run is more than 26 hours old." For a daily job, that's one day plus two hours of slack.
QUIZ
Why keep the raw records instead of only daily totals?
Sign in to track lesson progress and earn a certificate.SIGN IN TO SAVE PROGRESS