November 9 · Make the refresh safe before the handoff
MaDS Databases & SQL
One question will organize today
If the source changes tonight, can tomorrow’s analyst trust the database—and can the receiving team explain why?
Course source and adaptation
Today’s structure follows Alex Reinhart’s The Data Pipeline. His end-to-end pipeline, deployment, and monitoring ideas are adapted to the two Fall 2026 client databases and their November 13 handoff.
By the end of class
You should be able to:
draw the project pipeline from source to client result,
define an idempotent refresh and its transaction boundary,
with psycopg.connect(conninfo) as conn:with conn.cursor() as cur: load_stage(cur, rows) validate_stage(cur) merge_trusted(cur)# commit on clean exit; rollback on exception
The boundary should match the unit the receiver can safely retry.
Checkpoint 2 · Predict the second run
Take one current load step. Predict row counts after run 1, run 2, and a run interrupted halfway through.
Write the constraint, transaction boundary, and recovery command that make those predictions true.
Validation has layers
Layer
Example
File
expected columns; nonempty; parseable
Row
valid timestamp; latitude range
Table
unique business key; foreign keys resolve
Batch
plausible count and date coverage
Domain
no negative fatalities; charger type recognized
Client
published metric still uses comparable coverage
Missing data and failed data differ
Missing in source: an evidence limitation.
Rejected by validation: a pipeline result.
Not downloaded: an operational failure.
Filtered by design: a documented choice.
Do not collapse them into NULL without provenance.
Monitor the pipeline, not just the server
Track at least:
last successful source timestamp,
rows read, accepted, rejected, inserted, updated,
minimum/maximum business date,
duration and status by step,
a domain metric that should not jump silently.
Drift can invalidate a successful run
The code exits zero. The table loads. The client answer is still wrong.
Possible causes:
source categories changed,
geographic coverage changed,
a field’s unit changed,
revision policy changed,
client meaning changed.
Checkpoint 3 · Design the handoff alarm
Choose one failure the receiving team might miss. Define the signal, threshold, owner, and first diagnostic command.
Prefer a check tied to the client result over “server is running.”
The runbook begins with smallest success
The receiver should see:
prerequisites and safe credentials mechanism,
one command to connect,
one command for a small dry run,
expected output and validation values,
full refresh command,
rollback/retry instructions,
escalation and known issues.
Project transfer
Run the builder refresh twice. Capture counts, coverage, validation output, and failure/recovery behavior for the handoff pack.
Do not demonstrate against undocumented local state.
Homework starts here
Homework 2 reuses today’s evidence:
pipeline map,
rerun prediction and result,
forced failure result,
receiver-centered smallest-success command.
The pattern to keep
start from the client decision → name every contract → stage and validate → write atomically → prove the rerun → monitor meaning → document smallest success
Next: call SQL safely from Python and make one project result runnable by a receiver.