Server: verify Phase 1 end to end against PostgreSQL 17

Set up the dev environment (uv-managed CPython 3.14.7, postgres:17 in a
Podman container) and ran the skeleton for real: migrations apply, the
API serves /api/v1/health and /healthz, the worker claims a job and
drains it, 12/12 tests pass with nothing skipped.

The schema-drift test failed on its first real run and found a genuine
problem: Postgres reflects a varchar default as 'x'::character varying
while the model renders 'x', so all ten string defaults read as
permanent drift. Left alone that is the failure mode where you learn to
ignore the test and then miss the one real change. Add schema_compare.py,
a normaliser shared by migrations/env.py and the test so autogenerate and
the test can never disagree about what counts as a difference. A real
default change still fails it.

Also: ruff import-order fix in captures.py, and the README gains the
uv + Podman dev setup, the expected test count, and the CREATE DATABASE
privilege the drift test needs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thomas KarnerandClaude Opus 5 committed 2026-09-21 00:30:52 +02:00
1 parent 8a51e3d95e
commit 5d16ded553
6 files changed
+99 -9

No files matched your search

+1 -1
View File
@@ -19,6 +19,7 @@ from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
Column,
DateTime,
Float,
ForeignKey,
@@ -27,7 +28,6 @@ from sqlalchemy import (
String,
Table,
Text,
Column,
Uuid,
func,
)
+49
View File
@@ -0,0 +1,49 @@
"""Shared Alembic comparison options.
Used by both ``migrations/env.py`` and the schema-drift test, so autogenerate
and the test can never disagree about what counts as a difference.
"""
from __future__ import annotations
from typing import Any
def _normalise_default(value: Any) -> str:
"""Strip a Postgres type cast and the SQL quoting from a default.
Postgres reflects a varchar default as ``'viewer'::character varying``
while the model's metadata renders it as ``'viewer'``. Compared literally,
every string default in the schema looks like drift, forever -- which
trains you to ignore the one time it isn't.
"""
text = str(value).strip()
if "::" in text:
text = text.split("::", 1)[0]
return text.strip().strip("'").strip().lower()
def compare_server_default(
context: Any,
inspected_column: Any,
metadata_column: Any,
inspected_default: Any,
metadata_default: Any,
rendered_metadata_default: Any,
) -> bool | None:
"""Return True when the defaults genuinely differ.
Returning None hands the decision back to Alembic, which is what we want
whenever one side has no default at all -- that IS a real difference and
Alembic's own logic reports it correctly.
"""
if inspected_default is None or rendered_metadata_default is None:
return None
return _normalise_default(inspected_default) != _normalise_default(rendered_metadata_default)
# One place to define what "compare the schema" means.
COMPARE_OPTS: dict[str, Any] = {
"compare_type": True,
"compare_server_default": compare_server_default,
}