diff --git a/swh/vault/__init__.py b/swh/vault/__init__.py --- a/swh/vault/__init__.py +++ b/swh/vault/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2020 The Software Heritage developers +# Copyright (C) 2018-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -15,8 +15,10 @@ BACKEND_TYPES: Dict[str, str] = { "remote": ".api.client.RemoteVaultClient", - "local": ".backend.VaultBackend", + "postgresql": ".backend.VaultBackend", "memory": ".in_memory_backend.InMemoryVaultBackend", + # deprecated + "local": ".backend.VaultBackend", } @@ -53,3 +55,6 @@ module = importlib.import_module(module_path, package=__package__) Vault = getattr(module, class_name) return Vault(**kwargs) + + +get_datastore = get_vault diff --git a/swh/vault/backend.py b/swh/vault/backend.py --- a/swh/vault/backend.py +++ b/swh/vault/backend.py @@ -68,6 +68,8 @@ Backend for the Software Heritage Vault. """ + current_version = 4 + def __init__(self, **config): self.config = config self.cache = VaultCache(**config["cache"]) diff --git a/swh/vault/sql/30-schema.sql b/swh/vault/sql/30-schema.sql --- a/swh/vault/sql/30-schema.sql +++ b/swh/vault/sql/30-schema.sql @@ -1,13 +1,3 @@ -create table if not exists dbversion -( - version int primary key, - release timestamptz not null, - description text not null -); -comment on table dbversion is 'Schema update tracking'; -insert into dbversion (version, release, description) - values (4, now(), 'Initial version'); - create domain obj_hash as bytea; create type bundle_type as enum ('flat', 'gitfast', 'git_bare'); diff --git a/swh/vault/tests/conftest.py b/swh/vault/tests/conftest.py --- a/swh/vault/tests/conftest.py +++ b/swh/vault/tests/conftest.py @@ -3,17 +3,19 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +from functools import partial import os from typing import Any, Dict import pkg_resources.extern.packaging.version import pytest +from pytest_postgresql import factories import yaml -from swh.core.db.pytest_plugin import postgresql_fact -from swh.storage.tests import SQL_DIR as STORAGE_SQL_DIR -import swh.vault +from swh.core.db.pytest_plugin import initialize_database_for_module, postgresql_fact +from swh.storage.postgresql.db import Db as StorageDb from swh.vault import get_vault +from swh.vault.backend import VaultBackend os.environ["LC_ALL"] = "C.UTF-8" @@ -34,14 +36,23 @@ yield pathlib.Path(tmpdir) -VAULT_SQL_DIR = os.path.join(os.path.dirname(swh.vault.__file__), "sql") - +storage_postgresql_proc = factories.postgresql_proc( + dbname="storage", + load=[ + partial(initialize_database_for_module, "storage", StorageDb.current_version) + ], +) -postgres_vault = postgresql_fact( - "postgresql_proc", dbname="vault", dump_files=f"{VAULT_SQL_DIR}/*.sql" +vault_postgresql_proc = factories.postgresql_proc( + dbname="vault", + load=[ + partial(initialize_database_for_module, "vault", VaultBackend.current_version) + ], ) + +postgres_vault = postgresql_fact("vault_postgresql_proc") postgres_storage = postgresql_fact( - "postgresql_proc", dbname="storage", dump_files=f"{STORAGE_SQL_DIR}/*.sql" + "storage_postgresql_proc", no_db_drop=True, # keep the db for performance reasons )