From 0c5fdc7feba521e313b24a75ea2bed4f7a520918 Mon Sep 17 00:00:00 2001
From: "Antoine R. Dumont (@ardumont)" <ardumont@softwareheritage.org>
Date: Fri, 3 Jun 2022 11:39:33 +0200
Subject: [PATCH] Set current_version attribute to postgresql datastore

Related to T4305
---
 requirements-swh.txt            |  2 +-
 swh/indexer/storage/__init__.py | 10 ++++------
 swh/indexer/storage/db.py       |  3 +--
 swh/indexer/tests/conftest.py   |  5 ++---
 4 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/requirements-swh.txt b/requirements-swh.txt
index fd8a3447..52654a75 100644
--- a/requirements-swh.txt
+++ b/requirements-swh.txt
@@ -1,4 +1,4 @@
-swh.core[db,http] >= 0.14.0
+swh.core[db,http] >= 2.9
 swh.model >= 0.0.15
 swh.objstorage >= 0.2.2
 swh.scheduler >= 0.5.2
diff --git a/swh/indexer/storage/__init__.py b/swh/indexer/storage/__init__.py
index 1dc9fc26..470cf795 100644
--- a/swh/indexer/storage/__init__.py
+++ b/swh/indexer/storage/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2020  The Software Heritage developers
+# Copyright (C) 2015-2022  The Software Heritage developers
 # See the AUTHORS file at the top-level directory of this distribution
 # License: GNU General Public License version 3, or any later version
 # See top-level LICENSE file for more information
@@ -120,7 +120,9 @@ def check_id_duplicates(data):
 
 
 class IndexerStorage:
-    """SWH Indexer Storage"""
+    """SWH Indexer Storage Datastore"""
+
+    current_version = 134
 
     def __init__(self, db, min_pool_conns=1, max_pool_conns=10, journal_writer=None):
         """
@@ -152,10 +154,6 @@ class IndexerStorage:
         if db is not self._db:
             db.put_conn()
 
-    @db_transaction()
-    def get_current_version(self, *, db=None, cur=None):
-        return db.current_version
-
     @timed
     @db_transaction()
     def check_config(self, *, check_write, db=None, cur=None):
diff --git a/swh/indexer/storage/db.py b/swh/indexer/storage/db.py
index c8dbb12e..cb0ae0a9 100644
--- a/swh/indexer/storage/db.py
+++ b/swh/indexer/storage/db.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2018  The Software Heritage developers
+# Copyright (C) 2015-2022  The Software Heritage developers
 # See the AUTHORS file at the top-level directory of this distribution
 # License: GNU General Public License version 3, or any later version
 # See top-level LICENSE file for more information
@@ -16,7 +16,6 @@ class Db(BaseDb):
     """Proxy to the SWH Indexer DB, with wrappers around stored procedures"""
 
     content_mimetype_hash_keys = ["id", "indexer_configuration_id"]
-    current_version = 134
 
     def _missing_from_list(
         self, table: str, data: Iterable[Dict], hash_keys: List[str], cur=None
diff --git a/swh/indexer/tests/conftest.py b/swh/indexer/tests/conftest.py
index cef62d3f..b9211abc 100644
--- a/swh/indexer/tests/conftest.py
+++ b/swh/indexer/tests/conftest.py
@@ -14,8 +14,7 @@ from pytest_postgresql import factories
 import yaml
 
 from swh.core.db.pytest_plugin import initialize_database_for_module
-from swh.indexer.storage import get_indexer_storage
-from swh.indexer.storage.db import Db as IndexerDb
+from swh.indexer.storage import IndexerStorage, get_indexer_storage
 from swh.objstorage.factory import get_objstorage
 from swh.storage import get_storage
 
@@ -33,7 +32,7 @@ idx_postgresql_proc = factories.postgresql_proc(
         partial(
             initialize_database_for_module,
             modname="indexer",
-            version=IndexerDb.current_version,
+            version=IndexerStorage.current_version,
         )
     ],
 )
-- 
GitLab