@cumulus/db 19.2.0-alpha.1 → 20.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/lib/granule.d.ts +9 -0
- package/dist/lib/granule.js +21 -1
- package/dist/migrations/20240125171703_update_granule_execution_cumulus_id_type.js +0 -4
- package/dist/migrations/20240728101230_add_table_indexes.js +0 -8
- package/dist/search/StatsSearch.js +1 -2
- package/dist/search/queries.js +11 -1
- package/dist/test-utils.js +1 -1
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export { translateApiReconReportToPostgresReconReport, translatePostgresReconRep
|
|
|
30
30
|
export { getCollectionsByGranuleIds, getUniqueCollectionsByGranuleFilter, } from './lib/collection';
|
|
31
31
|
export { batchDeleteExecutionFromDatabaseByCumulusCollectionId, executionArnsFromGranuleIdsAndWorkflowNames, getApiExecutionCumulusIds, getApiGranuleExecutionCumulusIdsByExecution, getExecutionInfoByGranuleCumulusId, getWorkflowNameIntersectFromGranuleIds, newestExecutionArnFromGranuleIdWorkflowName, } from './lib/execution';
|
|
32
32
|
export { getFilesAndGranuleInfoQuery, } from './lib/file';
|
|
33
|
-
export { getApiGranuleCumulusIds, getApiGranuleExecutionCumulusIds, getGranuleCollectionId, getUniqueGranuleByGranuleId, getGranuleByUniqueColumns, upsertGranuleWithExecutionJoinRecord, getGranulesByApiPropertiesQuery, getGranulesByGranuleId, getGranuleAndCollection, } from './lib/granule';
|
|
33
|
+
export { getApiGranuleCumulusIds, getApiGranuleExecutionCumulusIds, getGranuleCollectionId, getUniqueGranuleByGranuleId, getGranuleByUniqueColumns, upsertGranuleWithExecutionJoinRecord, getGranulesByApiPropertiesQuery, getGranulesByGranuleId, getGranuleAndCollection, updateBatchGranulesCollection, } from './lib/granule';
|
|
34
34
|
export { QuerySearchClient, } from './lib/QuerySearchClient';
|
|
35
35
|
export { AsyncOperationSearch, } from './search/AsyncOperationSearch';
|
|
36
36
|
export { CollectionSearch, } from './search/CollectionSearch';
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getApiExecutionCumulusIds = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.batchDeleteExecutionFromDatabaseByCumulusCollectionId = exports.getUniqueCollectionsByGranuleFilter = exports.getCollectionsByGranuleIds = exports.translatePostgresReconReportToApiReconReport = exports.translateApiReconReportToPostgresReconReport = exports.translatePostgresPdrToApiPdr = exports.translateApiPdrToPostgresPdr = exports.translatePostgresGranuleResultToApiGranule = exports.translatePostgresGranuleToApiGranule = exports.translateApiGranuleToPostgresGranuleWithoutNilsRemoved = exports.translateApiGranuleToPostgresGranule = exports.translatePostgresExecutionToApiExecution = exports.translateApiExecutionToPostgresExecutionWithoutNilsRemoved = exports.translateApiExecutionToPostgresExecution = exports.translateApiRuleToPostgresRuleRaw = exports.translateApiRuleToPostgresRule = exports.translatePostgresRuleToApiRule = exports.translatePostgresProviderToApiProvider = exports.translateApiProviderToPostgresProvider = exports.translatePostgresCollectionToApiCollection = exports.translateApiCollectionToPostgresCollection = exports.translatePostgresFileToApiFile = exports.translateApiFiletoPostgresFile = exports.translatePostgresAsyncOperationToApiAsyncOperation = exports.translateApiAsyncOperationToPostgresAsyncOperation = exports.nullifyUndefinedProviderValues = exports.validateProviderHost = exports.migrationDir = exports.TableNames = exports.createRejectableTransaction = exports.localStackConnectionEnv = exports.getKnexConfig = exports.getKnexClient = exports.isCollisionError = exports.generateLocalTestDb = exports.fakeRuleRecordFactory = exports.fakeReconciliationReportRecordFactory = exports.fakeProviderRecordFactory = exports.fakePdrRecordFactory = exports.fakeGranuleRecordFactory = exports.fakeFileRecordFactory = exports.fakeExecutionRecordFactory = exports.fakeCollectionRecordFactory = exports.fakeAsyncOperationRecordFactory = exports.destroyLocalTestDb = exports.deleteTestDatabase = exports.createTestDatabase = exports.Knex = void 0;
|
|
27
|
-
exports.RulePgModel = exports.ReconciliationReportPgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.ReconciliationReportSearch = exports.StatsSearch = exports.RuleSearch = exports.ProviderSearch = exports.PdrSearch = exports.GranuleSearch = exports.ExecutionSearch = exports.CollectionSearch = exports.AsyncOperationSearch = exports.QuerySearchClient = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getFilesAndGranuleInfoQuery = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.getWorkflowNameIntersectFromGranuleIds = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = void 0;
|
|
27
|
+
exports.RulePgModel = exports.ReconciliationReportPgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.ReconciliationReportSearch = exports.StatsSearch = exports.RuleSearch = exports.ProviderSearch = exports.PdrSearch = exports.GranuleSearch = exports.ExecutionSearch = exports.CollectionSearch = exports.AsyncOperationSearch = exports.QuerySearchClient = exports.updateBatchGranulesCollection = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getFilesAndGranuleInfoQuery = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.getWorkflowNameIntersectFromGranuleIds = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = void 0;
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
29
|
var knex_1 = require("knex");
|
|
30
30
|
Object.defineProperty(exports, "Knex", { enumerable: true, get: function () { return knex_1.Knex; } });
|
|
@@ -111,6 +111,7 @@ Object.defineProperty(exports, "upsertGranuleWithExecutionJoinRecord", { enumera
|
|
|
111
111
|
Object.defineProperty(exports, "getGranulesByApiPropertiesQuery", { enumerable: true, get: function () { return granule_1.getGranulesByApiPropertiesQuery; } });
|
|
112
112
|
Object.defineProperty(exports, "getGranulesByGranuleId", { enumerable: true, get: function () { return granule_1.getGranulesByGranuleId; } });
|
|
113
113
|
Object.defineProperty(exports, "getGranuleAndCollection", { enumerable: true, get: function () { return granule_1.getGranuleAndCollection; } });
|
|
114
|
+
Object.defineProperty(exports, "updateBatchGranulesCollection", { enumerable: true, get: function () { return granule_1.updateBatchGranulesCollection; } });
|
|
114
115
|
var QuerySearchClient_1 = require("./lib/QuerySearchClient");
|
|
115
116
|
Object.defineProperty(exports, "QuerySearchClient", { enumerable: true, get: function () { return QuerySearchClient_1.QuerySearchClient; } });
|
|
116
117
|
var AsyncOperationSearch_1 = require("./search/AsyncOperationSearch");
|
package/dist/lib/granule.d.ts
CHANGED
|
@@ -114,4 +114,13 @@ export declare const getGranuleAndCollection: (knexOrTransaction: Knex | Knex.Tr
|
|
|
114
114
|
* @returns {Promise<PostgresGranuleRecord[]>} The returned list of records
|
|
115
115
|
*/
|
|
116
116
|
export declare const getGranulesByGranuleId: (knexOrTransaction: Knex | Knex.Transaction, granuleId: string) => Promise<PostgresGranuleRecord[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Update a list of granuleIds to a new collection_cumulus_id in postgres
|
|
119
|
+
*
|
|
120
|
+
* @param {Knex} knex - DB client or transaction
|
|
121
|
+
* @param {Array<String>} granuleIds - list of Granule IDs
|
|
122
|
+
* @param {number} collectionCumulusId - collection_cumulus_id to update to
|
|
123
|
+
* @returns {Promise<void>}
|
|
124
|
+
*/
|
|
125
|
+
export declare const updateBatchGranulesCollection: (knex: Knex, granuleIds: Array<String>, collectionCumulusId: number) => Promise<void>;
|
|
117
126
|
//# sourceMappingURL=granule.d.ts.map
|
package/dist/lib/granule.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getGranulesByGranuleId = exports.getGranuleAndCollection = exports.getGranulesByApiPropertiesQuery = exports.getApiGranuleExecutionCumulusIds = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getApiGranuleCumulusIds = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleCollectionId = void 0;
|
|
6
|
+
exports.updateBatchGranulesCollection = exports.getGranulesByGranuleId = exports.getGranuleAndCollection = exports.getGranulesByApiPropertiesQuery = exports.getApiGranuleExecutionCumulusIds = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getApiGranuleCumulusIds = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleCollectionId = void 0;
|
|
7
7
|
const Collections_1 = require("@cumulus/message/Collections");
|
|
8
8
|
const errors_1 = require("@cumulus/errors");
|
|
9
9
|
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
@@ -12,6 +12,7 @@ const granule_1 = require("../models/granule");
|
|
|
12
12
|
const granules_executions_1 = require("../models/granules-executions");
|
|
13
13
|
const { deprecate } = require('@cumulus/common/util');
|
|
14
14
|
const { TableNames } = require('../tables');
|
|
15
|
+
const log = new logger_1.default({ sender: '@cumulus/db/lib/granules' });
|
|
15
16
|
const getGranuleCollectionId = async (knexOrTransaction, granule) => {
|
|
16
17
|
const collectionPgModel = new collection_1.CollectionPgModel();
|
|
17
18
|
const collection = await collectionPgModel.get(knexOrTransaction, { cumulus_id: granule.collection_cumulus_id });
|
|
@@ -248,4 +249,23 @@ const getGranulesByGranuleId = async (knexOrTransaction, granuleId) => {
|
|
|
248
249
|
return records;
|
|
249
250
|
};
|
|
250
251
|
exports.getGranulesByGranuleId = getGranulesByGranuleId;
|
|
252
|
+
/**
|
|
253
|
+
* Update a list of granuleIds to a new collection_cumulus_id in postgres
|
|
254
|
+
*
|
|
255
|
+
* @param {Knex} knex - DB client or transaction
|
|
256
|
+
* @param {Array<String>} granuleIds - list of Granule IDs
|
|
257
|
+
* @param {number} collectionCumulusId - collection_cumulus_id to update to
|
|
258
|
+
* @returns {Promise<void>}
|
|
259
|
+
*/
|
|
260
|
+
const updateBatchGranulesCollection = async (knex, granuleIds, collectionCumulusId) => {
|
|
261
|
+
const { granules: granulesTable, } = TableNames;
|
|
262
|
+
try {
|
|
263
|
+
await knex(granulesTable).whereIn('granule_id', granuleIds).update({ collection_cumulus_id: collectionCumulusId });
|
|
264
|
+
}
|
|
265
|
+
catch (thrownError) {
|
|
266
|
+
log.error(`Write Granules failed: ${JSON.stringify(thrownError)}`);
|
|
267
|
+
throw thrownError;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
exports.updateBatchGranulesCollection = updateBatchGranulesCollection;
|
|
251
271
|
//# sourceMappingURL=granule.js.map
|
|
@@ -6,10 +6,6 @@ const up = async (knex) => {
|
|
|
6
6
|
await knex.raw('ALTER TABLE executions ALTER COLUMN cumulus_id TYPE BIGINT, ALTER COLUMN parent_cumulus_id TYPE BIGINT');
|
|
7
7
|
await knex.raw('ALTER TABLE granules_executions ALTER COLUMN granule_cumulus_id TYPE BIGINT, ALTER COLUMN execution_cumulus_id TYPE BIGINT');
|
|
8
8
|
await knex.raw('ALTER TABLE pdrs ALTER COLUMN execution_cumulus_id TYPE BIGINT');
|
|
9
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) executions');
|
|
10
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) files');
|
|
11
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) granules_executions');
|
|
12
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) pdrs');
|
|
13
9
|
};
|
|
14
10
|
exports.up = up;
|
|
15
11
|
const down = async () => {
|
|
@@ -18,14 +18,6 @@ const up = async (knex) => {
|
|
|
18
18
|
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS pdrs_provider_collection_cumulus_id_name_index ON pdrs(provider_cumulus_id, collection_cumulus_id, name)');
|
|
19
19
|
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS providers_updated_at_index ON providers(updated_at)');
|
|
20
20
|
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS rules_updated_at_index ON rules(updated_at)');
|
|
21
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) async_operations');
|
|
22
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) collections');
|
|
23
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) executions');
|
|
24
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) files');
|
|
25
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) granules');
|
|
26
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) pdrs');
|
|
27
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) providers');
|
|
28
|
-
await knex.raw('VACUUM (ANALYZE, VERBOSE) rules');
|
|
29
21
|
};
|
|
30
22
|
exports.up = up;
|
|
31
23
|
const down = async (knex) => {
|
|
@@ -24,9 +24,8 @@ const infixMapping = {
|
|
|
24
24
|
class StatsSearch extends BaseSearch_1.BaseSearch {
|
|
25
25
|
constructor(event, type) {
|
|
26
26
|
const { field, ...queryStringParameters } = event.queryStringParameters || {};
|
|
27
|
-
super({ queryStringParameters }, type);
|
|
27
|
+
super({ queryStringParameters: { ...queryStringParameters, limit: null } }, type);
|
|
28
28
|
this.field = field ?? 'status';
|
|
29
|
-
this.dbQueryParameters = (0, omit_1.default)(this.dbQueryParameters, ['limit', 'offset']);
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* Formats the postgres records into an API stats/aggregate response
|
package/dist/search/queries.js
CHANGED
|
@@ -33,6 +33,13 @@ const regexes = {
|
|
|
33
33
|
exists: /^(.*)__exists$/,
|
|
34
34
|
range: /^(.*)__(from|to)$/,
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Based on PostgreSQL documentation, when using LIMIT, it is important to use
|
|
38
|
+
* an ORDER BY clause that constrains the result rows into a unique order.
|
|
39
|
+
* The following is the default sort column and order for the pagination.
|
|
40
|
+
*/
|
|
41
|
+
const defaultSortColumn = 'cumulus_id';
|
|
42
|
+
const defaultSortOrder = 'asc';
|
|
36
43
|
/**
|
|
37
44
|
* Convert 'exists' query fields to db query parameters from api query string fields
|
|
38
45
|
*
|
|
@@ -166,7 +173,7 @@ const convertTerms = (type, queryStringFields) => {
|
|
|
166
173
|
*/
|
|
167
174
|
const convertSort = (type, queryStringParameters) => {
|
|
168
175
|
const sortArray = [];
|
|
169
|
-
const { sort_by: sortBy, sort_key: sortKey } = queryStringParameters;
|
|
176
|
+
const { sort_by: sortBy, sort_key: sortKey, limit } = queryStringParameters;
|
|
170
177
|
let { order } = queryStringParameters;
|
|
171
178
|
if (sortBy) {
|
|
172
179
|
order = order ?? 'asc';
|
|
@@ -180,6 +187,9 @@ const convertSort = (type, queryStringParameters) => {
|
|
|
180
187
|
return Object.keys(queryParam ?? {}).map((key) => sortArray.push({ column: key, order }));
|
|
181
188
|
});
|
|
182
189
|
}
|
|
190
|
+
if (limit !== null) {
|
|
191
|
+
sortArray.push({ column: defaultSortColumn, order: defaultSortOrder });
|
|
192
|
+
}
|
|
183
193
|
return sortArray;
|
|
184
194
|
};
|
|
185
195
|
/**
|
package/dist/test-utils.js
CHANGED
|
@@ -104,7 +104,7 @@ exports.fakeFileRecordFactory = fakeFileRecordFactory;
|
|
|
104
104
|
const fakeAsyncOperationRecordFactory = (params) => ({
|
|
105
105
|
id: (0, uuid_1.v4)(),
|
|
106
106
|
description: (0, crypto_random_string_1.default)({ length: 10 }),
|
|
107
|
-
operation_type: '
|
|
107
|
+
operation_type: 'Reconciliation Report',
|
|
108
108
|
status: 'RUNNING',
|
|
109
109
|
output: { test: 'output' },
|
|
110
110
|
task_arn: (0, crypto_random_string_1.default)({ length: 3 }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/db",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.0.1",
|
|
4
4
|
"description": "Utilities for working with the Cumulus DB",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@aws-sdk/client-secrets-manager": "^3.621.0",
|
|
36
|
-
"@cumulus/aws-client": "
|
|
37
|
-
"@cumulus/common": "
|
|
38
|
-
"@cumulus/errors": "
|
|
39
|
-
"@cumulus/logger": "
|
|
40
|
-
"@cumulus/message": "
|
|
41
|
-
"@cumulus/types": "
|
|
36
|
+
"@cumulus/aws-client": "20.0.1",
|
|
37
|
+
"@cumulus/common": "20.0.1",
|
|
38
|
+
"@cumulus/errors": "20.0.1",
|
|
39
|
+
"@cumulus/logger": "20.0.1",
|
|
40
|
+
"@cumulus/message": "20.0.1",
|
|
41
|
+
"@cumulus/types": "20.0.1",
|
|
42
42
|
"crypto-random-string": "^3.2.0",
|
|
43
43
|
"is-valid-hostname": "1.0.2",
|
|
44
44
|
"knex": "2.4.1",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/uuid": "^8.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "3bfee176543ede36c4ca902f4af9c6d108454468"
|
|
54
54
|
}
|