From 4f7de096bed74233387ae64abfe61aa36c65db67 Mon Sep 17 00:00:00 2001 From: Scott Searcy Date: Mon, 6 May 2024 15:13:12 -0700 Subject: [PATCH] Upgrade to SQLAlchemy 2.0 --- .env.example | 2 +- docs/config.rst | 2 +- meshinfo/models/__init__.py | 4 ++-- pyproject.toml | 8 ++++---- requirements.txt | 15 ++++++++++----- tests/conftest.py | 2 +- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.env.example b/.env.example index 5a75f2e..15a4f17 100644 --- a/.env.example +++ b/.env.example @@ -8,4 +8,4 @@ MESH_INFO_LOG_LEVEL="INFO" MESH_INFO_MAP_TILE_URL="" MESH_INFO_MAP_TILE_ATTRIBUTION="" #MESH_INFO_DATA_DIR="/var/lib/mesh-info" -#MESH_INFO_DB_URL="postgresql+psycopg2://postgres:postgres@localhost:5432/postgres" +#MESH_INFO_DB_URL="postgresql+psycopg://postgres:postgres@localhost:5432/postgres" diff --git a/docs/config.rst b/docs/config.rst index 59f99b5..0ab4ba3 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -20,7 +20,7 @@ Example MESH_INFO_LOG_LEVEL=INFO MESH_INFO_MAP_TILE_URL="https://tiles.stadiamaps.com/tiles/stamen_terrain/{z}/{x}/{y}{r}.png" MESH_INFO_MAP_TILE_ATTRIBUTION='© Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap' - MESH_INFO_DB_URL="postgresql+psycopg2://postgres:password@localhost:5432/postgres" + MESH_INFO_DB_URL="postgresql+psycopg://postgres:password@localhost:5432/postgres" Options diff --git a/meshinfo/models/__init__.py b/meshinfo/models/__init__.py index 6b1fdfa..6158e4a 100644 --- a/meshinfo/models/__init__.py +++ b/meshinfo/models/__init__.py @@ -22,11 +22,11 @@ def get_engine(settings): - return create_engine(future=True, **attr.asdict(settings)) + return create_engine(**attr.asdict(settings)) def get_session_factory(engine) -> sessionmaker: - factory = sessionmaker(engine, future=True) + factory = sessionmaker(engine) return factory diff --git a/pyproject.toml b/pyproject.toml index 94995fc..d16c6d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ "gunicorn ~= 22.0", "pendulum ~= 2.1", "platformdirs ~= 2.0", - "psycopg2 ~= 2.9", + "psycopg ~= 3.0", "pyramid ~= 2.0", "pyramid-jinja2 ~= 2.10", "pyramid-retry ~= 2.1", @@ -35,7 +35,7 @@ dependencies = [ "rich ~= 13.3", "rrdtool", "structlog ~= 23.2", - "sqlalchemy ~= 1.4", + "sqlalchemy ~= 2.0", "transaction ~= 3.0", "zope.sqlalchemy ~= 3.0", ] @@ -55,11 +55,11 @@ tests = [ "WebTest", "flake8-bugbear", "flake8", - "mypy ~= 1.5.1", + "mypy ~= 1.10", "pytest-asyncio", "pytest-cov", "pytest-mock", - "pytest-postgresql < 4.0", + "pytest-postgresql", "pytest", ] dev = [ diff --git a/requirements.txt b/requirements.txt index cde7d92..1526605 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.11 # by the following command: # -# pip-compile --output-file=requirements.txt --resolver=backtracking pyproject.toml +# pip-compile --output-file=requirements.txt pyproject.toml # aiohttp==3.8.6 # via mesh-info (pyproject.toml) @@ -51,7 +51,9 @@ multidict==6.0.4 # aiohttp # yarl packaging==23.2 - # via gunicorn + # via + # gunicorn + # zope-sqlalchemy pastedeploy==3.0.1 # via plaster-pastedeploy pendulum==2.1.2 @@ -64,7 +66,7 @@ plaster-pastedeploy==1.0.1 # via pyramid platformdirs==2.6.2 # via mesh-info (pyproject.toml) -psycopg2==2.9.9 +psycopg==3.1.18 # via mesh-info (pyproject.toml) pygments==2.16.1 # via rich @@ -95,7 +97,7 @@ rrdtool==0.1.16 # via mesh-info (pyproject.toml) six==1.16.0 # via python-dateutil -sqlalchemy==1.4.50 +sqlalchemy==2.0.30 # via # alembic # mesh-info (pyproject.toml) @@ -110,7 +112,10 @@ transaction==3.1.0 translationstring==1.4 # via pyramid typing-extensions==4.8.0 - # via alembic + # via + # alembic + # psycopg + # sqlalchemy venusian==3.0.0 # via pyramid webob==1.8.7 diff --git a/tests/conftest.py b/tests/conftest.py index 1bdbe85..21c7521 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,7 +57,7 @@ def dbengine(request, tmp_path): host = dbinfo.host port = dbinfo.port dbname = dbinfo.dbname - db_url = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{dbname}" + db_url = f"postgresql+psycopg://{user}:{password}@{host}:{port}/{dbname}" else: raise ValueError(f"Unknown param: {request.param!r}")