From 716e9271fd66814a5351bc192c716efd42657e09 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Jul 2026 21:52:32 +0000 Subject: [PATCH] Upgrade PostgreSQL adapter from psycopg2 to psycopg (psycopg 3) Rename the python.psycopg2 Salt state to python.psycopg and update its includes in the kingfisher collect, incremental and summarize states. The state installs the same build dependencies (python-dev, libpq-dev) required to compile psycopg[c] from source in production. Update the databases usage docs to import psycopg and call psycopg.connect(). Ref: open-contracting/software-development-handbook#162 Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01HfBXUB6Rgvqws9h7w7v9sP --- docs/use/databases.rst | 6 +++--- salt/kingfisher/collect/incremental.sls | 2 +- salt/kingfisher/collect/init.sls | 2 +- salt/kingfisher/summarize/init.sls | 2 +- salt/python/{psycopg2.sls => psycopg.sls} | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) rename salt/python/{psycopg2.sls => psycopg.sls} (60%) diff --git a/docs/use/databases.rst b/docs/use/databases.rst index dc463c1e..614ac5dc 100644 --- a/docs/use/databases.rst +++ b/docs/use/databases.rst @@ -122,15 +122,15 @@ Python `Python `__ is the programming language in which many OCDS tools are written. -Install the `psycopg2 `__ Python package. +Install the `psycopg `__ Python package. For security, remember to set ``sslmode`` to ``'require'``. .. code-block:: python - import psycopg2 + import psycopg - conn = psycopg2.connect( + conn = psycopg.connect( dbname='kingfisher_process', user='USER', password='PASSWORD', diff --git a/salt/kingfisher/collect/incremental.sls b/salt/kingfisher/collect/incremental.sls index 2e09a3b0..3c41ead8 100644 --- a/salt/kingfisher/collect/incremental.sls +++ b/salt/kingfisher/collect/incremental.sls @@ -1,7 +1,7 @@ {% from 'lib.sls' import create_user, set_cron_env %} include: - - python.psycopg2 + - python.psycopg - python_apps {% set entry = pillar.python_apps.kingfisher_collect %} diff --git a/salt/kingfisher/collect/init.sls b/salt/kingfisher/collect/init.sls index 9b9a65c1..54b3021b 100644 --- a/salt/kingfisher/collect/init.sls +++ b/salt/kingfisher/collect/init.sls @@ -3,7 +3,7 @@ include: - python.virtualenv - python.extensions # twisted - - python.psycopg2 + - python.psycopg {% set entry = pillar.kingfisher_collect %} {% set user = entry.user %} diff --git a/salt/kingfisher/summarize/init.sls b/salt/kingfisher/summarize/init.sls index 7c156350..4cafe4f4 100644 --- a/salt/kingfisher/summarize/init.sls +++ b/salt/kingfisher/summarize/init.sls @@ -1,7 +1,7 @@ {% from 'lib.sls' import create_user, set_cron_env %} include: - - python.psycopg2 + - python.psycopg - python_apps {% set entry = pillar.python_apps.kingfisher_summarize %} diff --git a/salt/python/psycopg2.sls b/salt/python/psycopg.sls similarity index 60% rename from salt/python/psycopg2.sls rename to salt/python/psycopg.sls index f3c2ca46..d9112da0 100644 --- a/salt/python/psycopg2.sls +++ b/salt/python/psycopg.sls @@ -1,8 +1,8 @@ include: - python -# https://www.psycopg.org/install/ -psycopg2: +# https://www.psycopg.org/psycopg3/docs/basic/install.html#local-installation +psycopg: pkg.installed: - pkgs: - python{{ salt['pillar.get']('python:version', 3) }}-dev