test: add provider postgres conformance

This commit is contained in:
tegwick 2026-06-16 07:33:34 +02:00
parent 1f2ac6666f
commit a1692c62e3
7 changed files with 347 additions and 16 deletions

View file

@ -90,9 +90,9 @@ class PostgresUserEngineStore:
return self.schema_version == LATEST_SCHEMA_VERSION
def migrate(self) -> None:
sql = _load_bootstrap_sql()
with self._cursor() as cursor:
cursor.execute(sql)
for statement in _bootstrap_sql_statements():
cursor.execute(statement)
self.connection.commit()
@contextmanager
@ -549,16 +549,20 @@ class PostgresUserEngineStore:
)
def _has_latest_schema(self) -> bool:
with self._cursor() as cursor:
cursor.execute(
"""
SELECT 1
FROM user_engine_schema_versions
WHERE version = %s
""",
(LATEST_SCHEMA_VERSION,),
)
return cursor.fetchone() is not None
try:
with self._cursor() as cursor:
cursor.execute(
"""
SELECT 1
FROM user_engine_schema_versions
WHERE version = %s
""",
(LATEST_SCHEMA_VERSION,),
)
return cursor.fetchone() is not None
except Exception:
self.connection.rollback()
return False
@contextmanager
def _cursor(self) -> Iterator[PostgresCursor]:
@ -624,3 +628,11 @@ def _load_bootstrap_sql() -> str:
return (repo_root / "migrations/postgres/0001_user_engine_store.sql").read_text(
encoding="utf-8"
)
def _bootstrap_sql_statements() -> tuple[str, ...]:
return tuple(
f"{statement.strip()};"
for statement in _load_bootstrap_sql().split(";")
if statement.strip()
)