Skip to content

[06] Postgres compatibility (dialect, BigInteger timestamps, DATABASE_URL, pool_pre_ping) - #25

Open
chondl wants to merge 4 commits into
cph-masterfrom
cph-postgres-compat
Open

[06] Postgres compatibility (dialect, BigInteger timestamps, DATABASE_URL, pool_pre_ping)#25
chondl wants to merge 4 commits into
cph-masterfrom
cph-postgres-compat

Conversation

@chondl

@chondl chondl commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Distinct re-arch step: Postgres/Cloud SQL support. Part of the cph-staging series.

chondl added 4 commits July 9, 2026 21:33
Lets the backend run against plain PostgreSQL (e.g. Cloud SQL) instead of
CockroachDB by exporting DATABASE_URL, without disturbing the existing PROD
CockroachDB path or local dev default. Retry behavior is selected from the
engine dialect (see src/db/transaction.py).
Introduce src/db/transaction.py with a run_transaction wrapper that keeps the
CockroachDB behavior unchanged (delegates to sqlalchemy_cockroachdb, imported
lazily) while adding a plain-SQLAlchemy transaction path for other dialects
(PostgreSQL). The Postgres path preserves retry-on-serialization-failure
(SQLSTATE 40001) semantics. Repoint the 13 db read/write/function modules to
import run_transaction from src.db.transaction instead of sqlalchemy_cockroachdb.
On Postgres, SQLAlchemy Integer maps to int4 (32-bit). TBA returns a ~1900
placeholder Unix timestamp (-2208988800) for matches/events with an unknown
time, which underflows int32 and aborts historical builds at 2006 with
psycopg2.errors.NumericValueOutOfRange. CockroachDB INT is 64-bit, so this
never surfaced on the production database. Widen the four timestamp columns
(match.time, match.predicted_time, event.time, team_event.time) to BigInteger;
this matches CockroachDB's width and is future-proof past the 2038 int32 limit.
A pooled connection left idle across the hourly-cron gap goes stale (Cloud SQL /
db-f1-micro / the Cloud SQL proxy reap idle connections). The next query then
raises 'server closed the connection unexpectedly', which 500s the ETL trigger
(/v3/site/update_curr_year) and silently stalls ingestion — on the mirror this
stopped offseason match schedules from appearing. pool_pre_ping reconnects
transparently; pool_recycle=1800 drops old connections proactively.

Deployed and verified on the staging mirror (backend rev 00014): the update
endpoint returns 200 repeatedly where it had been 500ing, and 2026iri ingested
its full match schedule.
@chondl chondl changed the title [re-arch] Postgres compatibility (dialect, BigInteger timestamps, DATABASE_URL) [06] Postgres compatibility (dialect, BigInteger timestamps, DATABASE_URL, pool_pre_ping) Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant