diff --git a/NEWS.md b/NEWS.md index ec3d3b064..36c07e8dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +## 2023-xx-xx v5.7.4 +* [MODSOURCE-722](https://issues.folio.org/browse/MODSOURCE-722) deleteMarcIndexersOldVersions: relation "marc_records_tracking" does not exist + ## 2023-11-09 v5.7.3 * [MODSOURCE-709](https://issues.folio.org/browse/MODSOURCE-709) MARC authority record is not created when use Job profile with match profile by absent subfield/field * [MODSOURCE-715](https://issues.folio.org/browse/MODSOURCE-715) Change API calls to central tenant for shared BIB diff --git a/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProvider.java b/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProvider.java index 2711e4c45..662887872 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProvider.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProvider.java @@ -9,9 +9,9 @@ */ public interface TenantDataProvider { /** - * Gets all module tenants. + * Gets all module tenants where the given database table exists. * * @return tenant ids */ - Future> getModuleTenants(); + Future> getModuleTenants(String table); } diff --git a/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProviderImpl.java b/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProviderImpl.java index 68d57b7e5..f1320e27d 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProviderImpl.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/services/TenantDataProviderImpl.java @@ -1,10 +1,10 @@ package org.folio.services; import io.vertx.core.Future; -import io.vertx.core.Promise; import io.vertx.core.Vertx; import io.vertx.sqlclient.Row; -import io.vertx.sqlclient.RowSet; +import io.vertx.sqlclient.Tuple; + import org.folio.rest.persist.PostgresClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -15,6 +15,7 @@ @Service public class TenantDataProviderImpl implements TenantDataProvider { + private static final String SUFFIX = "_mod_source_record_storage"; private Vertx vertx; @Autowired @@ -23,22 +24,21 @@ public TenantDataProviderImpl(Vertx vertx) { } @Override - public Future> getModuleTenants() { + public Future> getModuleTenants(String table) { PostgresClient pgClient = PostgresClient.getInstance(vertx); - Promise> promise = Promise.promise(); - String tenantQuery = "select nspname from pg_catalog.pg_namespace where nspname LIKE '%_mod_source_record_storage';"; - pgClient.select(tenantQuery, promise); - return promise.future() - .map(rowSet -> StreamSupport.stream(rowSet.spliterator(), false) - .map(this::mapToTenant) - .collect(Collectors.toList()) - ); + String tenantQuery = """ + select schemaname from pg_catalog.pg_tables + where schemaname LIKE $1 and tablename = $2 + """; + return pgClient.execute(tenantQuery, Tuple.of("%" + SUFFIX, table)) + .map(rowSet -> StreamSupport.stream(rowSet.spliterator(), false) + .map(this::mapToTenant) + .collect(Collectors.toList())); } private String mapToTenant(Row row) { - String nsTenant = row.getString("nspname"); - String suffix = "_mod_source_record_storage"; - int tenantNameLength = nsTenant.length() - suffix.length(); - return nsTenant.substring(0, tenantNameLength); + String schemaname = row.getString("schemaname"); + int tenantNameLength = schemaname.length() - SUFFIX.length(); + return schemaname.substring(0, tenantNameLength); } } diff --git a/mod-source-record-storage-server/src/main/java/org/folio/verticle/MarcIndexersVersionDeletionVerticle.java b/mod-source-record-storage-server/src/main/java/org/folio/verticle/MarcIndexersVersionDeletionVerticle.java index a649a70bf..9cf82724e 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/verticle/MarcIndexersVersionDeletionVerticle.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/verticle/MarcIndexersVersionDeletionVerticle.java @@ -57,7 +57,7 @@ public void start(Promise startFuture) { Future deleteOldMarcIndexerVersions() { LOGGER.info("Performing marc_indexers old versions deletion..."); long startTime = System.nanoTime(); - return tenantDataProvider.getModuleTenants() + return tenantDataProvider.getModuleTenants("marc_records_tracking") .onFailure(ar -> LOGGER.error("could not get the list of tenants to delete marc indexer versions", ar.getCause())) .compose(ar -> {