@cumulus/db 18.3.4 → 19.0.0
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/README.md +5 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +40 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +15 -4
- package/dist/lib/execution.d.ts +5 -0
- package/dist/lib/execution.js +16 -1
- package/dist/migrations/20240125171703_update_granule_execution_cumulus_id_type.d.ts +4 -0
- package/dist/migrations/20240125171703_update_granule_execution_cumulus_id_type.js +22 -0
- package/dist/migrations/20240126135619_granules_add_indexes.d.ts +4 -0
- package/dist/migrations/20240126135619_granules_add_indexes.js +19 -0
- package/dist/migrations/20240126165019_granules_update_constraints.d.ts +4 -0
- package/dist/migrations/20240126165019_granules_update_constraints.js +44 -0
- package/dist/migrations/20240606060726_alter_async_operations_add_operation_type_bulk_execution_delete.d.ts +4 -0
- package/dist/migrations/20240606060726_alter_async_operations_add_operation_type_bulk_execution_delete.js +43 -0
- package/dist/migrations/20240613174614_add_execution_parent_and_collection_indexes.d.ts +4 -0
- package/dist/migrations/20240613174614_add_execution_parent_and_collection_indexes.js +17 -0
- package/dist/migrations/20240617204826_update_executions_deletion_constraint.d.ts +4 -0
- package/dist/migrations/20240617204826_update_executions_deletion_constraint.js +14 -0
- package/dist/migrations/20240728101230_add_table_indexes.d.ts +4 -0
- package/dist/migrations/20240728101230_add_table_indexes.js +53 -0
- package/dist/models/execution.d.ts +2 -2
- package/dist/models/execution.js +1 -1
- package/dist/search/BaseSearch.d.ts +187 -0
- package/dist/search/BaseSearch.js +416 -0
- package/dist/search/CollectionSearch.d.ts +79 -0
- package/dist/search/CollectionSearch.js +162 -0
- package/dist/search/ExecutionSearch.d.ts +62 -0
- package/dist/search/ExecutionSearch.js +133 -0
- package/dist/search/GranuleSearch.d.ts +55 -0
- package/dist/search/GranuleSearch.js +109 -0
- package/dist/search/StatsSearch.d.ts +111 -0
- package/dist/search/StatsSearch.js +214 -0
- package/dist/search/field-mapping.d.ts +16 -0
- package/dist/search/field-mapping.js +304 -0
- package/dist/search/queries.d.ts +10 -0
- package/dist/search/queries.js +235 -0
- package/dist/translate/executions.d.ts +6 -0
- package/dist/translate/executions.js +32 -23
- package/dist/translate/granules.d.ts +25 -1
- package/dist/translate/granules.js +48 -27
- package/dist/types/search.d.ts +52 -0
- package/dist/types/search.js +3 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -31,6 +31,11 @@ Typically, there are two TypeScript interfaces describing each Cumulus data type
|
|
|
31
31
|
- `PostgresProvider`: Describes the data structure ready for insertion into the Cumulus Postgres database
|
|
32
32
|
- `PostgresProviderRecord`: Describes the data structure after retrieval from the Cumulus database. This data type usually includes extra required properties (such as the auto-incremented primary key field), since those properties will exist once a record has been created.
|
|
33
33
|
|
|
34
|
+
### BigInt cumulus_id columns
|
|
35
|
+
|
|
36
|
+
For the BigInt columns, knex returns postgres as "string" type. In order to use cumulus_id as a number, knex hook
|
|
37
|
+
postProcessResponse is configured to convert the return string from columns ending with "cumulus_id" to number.
|
|
38
|
+
|
|
34
39
|
## About Cumulus
|
|
35
40
|
|
|
36
41
|
Cumulus is a cloud-based data ingest, archive, distribution and management
|
package/dist/config.d.ts
CHANGED
|
@@ -35,6 +35,24 @@ export declare const getConnectionConfig: ({ env, secretsManager, }: {
|
|
|
35
35
|
env: NodeJS.ProcessEnv;
|
|
36
36
|
secretsManager?: SecretsManager | undefined;
|
|
37
37
|
}) => Promise<Knex.PgConnectionConfig>;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a string can be converted to a number
|
|
40
|
+
*
|
|
41
|
+
* @param bigIntValue - string to be converted to number
|
|
42
|
+
* @returns true if the string can be converted
|
|
43
|
+
* @throws - Throws error if the string can not be converted
|
|
44
|
+
*/
|
|
45
|
+
export declare const canSafelyConvertBigInt: (bigIntValue: string) => boolean;
|
|
46
|
+
declare type RecordTypeWithNumberIdField<T> = {
|
|
47
|
+
[P in keyof T]: number | T[P];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Convert cumulus id fields to number
|
|
51
|
+
*
|
|
52
|
+
* @param record - record to be converted
|
|
53
|
+
* @returns the converted record
|
|
54
|
+
*/
|
|
55
|
+
export declare const convertIdColumnsToNumber: <T extends Record<string, any>>(record: T) => RecordTypeWithNumberIdField<T>;
|
|
38
56
|
/**
|
|
39
57
|
* Given a NodeJS.ProcessEnv with configuration values, build and return Knex
|
|
40
58
|
* configuration
|
|
@@ -79,4 +97,5 @@ export declare const getKnexConfig: ({ env, secretsManager, }?: {
|
|
|
79
97
|
env?: NodeJS.ProcessEnv | undefined;
|
|
80
98
|
secretsManager?: SecretsManager | undefined;
|
|
81
99
|
}) => Promise<Knex.Config>;
|
|
100
|
+
export {};
|
|
82
101
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getKnexConfig = exports.getConnectionConfig = exports.getConnectionConfigEnv = exports.getSecretConnectionConfig = exports.isKnexDebugEnabled = exports.localStackConnectionEnv = void 0;
|
|
6
|
+
exports.getKnexConfig = exports.convertIdColumnsToNumber = exports.canSafelyConvertBigInt = exports.getConnectionConfig = exports.getConnectionConfigEnv = exports.getSecretConnectionConfig = exports.isKnexDebugEnabled = exports.localStackConnectionEnv = void 0;
|
|
4
7
|
const aws_client_1 = require("@cumulus/aws-client");
|
|
8
|
+
const mapValues_1 = __importDefault(require("lodash/mapValues"));
|
|
9
|
+
const isNull_1 = __importDefault(require("lodash/isNull"));
|
|
10
|
+
const isObject_1 = __importDefault(require("lodash/isObject"));
|
|
11
|
+
const isString_1 = __importDefault(require("lodash/isString"));
|
|
5
12
|
const common_1 = require("@cumulus/common");
|
|
6
13
|
exports.localStackConnectionEnv = {
|
|
7
14
|
PG_DATABASE: 'postgres',
|
|
@@ -76,6 +83,30 @@ const getConnectionConfig = async ({ env, secretsManager = aws_client_1.services
|
|
|
76
83
|
return await (0, exports.getConnectionConfigEnv)(env);
|
|
77
84
|
};
|
|
78
85
|
exports.getConnectionConfig = getConnectionConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Check if a string can be converted to a number
|
|
88
|
+
*
|
|
89
|
+
* @param bigIntValue - string to be converted to number
|
|
90
|
+
* @returns true if the string can be converted
|
|
91
|
+
* @throws - Throws error if the string can not be converted
|
|
92
|
+
*/
|
|
93
|
+
const canSafelyConvertBigInt = (bigIntValue) => {
|
|
94
|
+
if (BigInt(bigIntValue) > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
95
|
+
throw new Error(`Failed to convert to number: ${bigIntValue} exceeds max safe integer ${Number.MAX_SAFE_INTEGER}`);
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
};
|
|
99
|
+
exports.canSafelyConvertBigInt = canSafelyConvertBigInt;
|
|
100
|
+
/**
|
|
101
|
+
* Convert cumulus id fields to number
|
|
102
|
+
*
|
|
103
|
+
* @param record - record to be converted
|
|
104
|
+
* @returns the converted record
|
|
105
|
+
*/
|
|
106
|
+
const convertIdColumnsToNumber = (record) => (0, mapValues_1.default)(record, (value, key) => ((key.endsWith('cumulus_id') && !(0, isNull_1.default)(value) && (0, isString_1.default)(value) && (0, exports.canSafelyConvertBigInt)(value))
|
|
107
|
+
? Number(value)
|
|
108
|
+
: value));
|
|
109
|
+
exports.convertIdColumnsToNumber = convertIdColumnsToNumber;
|
|
79
110
|
/**
|
|
80
111
|
* Given a NodeJS.ProcessEnv with configuration values, build and return Knex
|
|
81
112
|
* configuration
|
|
@@ -136,6 +167,14 @@ const getKnexConfig = async ({ env = process.env, secretsManager = aws_client_1.
|
|
|
136
167
|
reapIntervalMillis: Number.parseInt(env.reapIntervalMillis ?? '1000', 10),
|
|
137
168
|
propagateCreateError: false,
|
|
138
169
|
},
|
|
170
|
+
// modify any knex query response to convert columns ending with "cumulus_id" from
|
|
171
|
+
// string | number to number
|
|
172
|
+
postProcessResponse: (result) => {
|
|
173
|
+
if (result && Array.isArray(result)) {
|
|
174
|
+
return result.map((row) => ((0, isObject_1.default)(row) ? (0, exports.convertIdColumnsToNumber)(row) : row));
|
|
175
|
+
}
|
|
176
|
+
return ((0, isObject_1.default)(result) ? (0, exports.convertIdColumnsToNumber)(result) : result);
|
|
177
|
+
},
|
|
139
178
|
};
|
|
140
179
|
knexConfig.acquireConnectionTimeout = env.acquireTimeoutMillis
|
|
141
180
|
? Number(env.acquireTimeoutMillis + 1000)
|
package/dist/index.d.ts
CHANGED
|
@@ -26,10 +26,15 @@ export { translateApiExecutionToPostgresExecution, translateApiExecutionToPostgr
|
|
|
26
26
|
export { translateApiGranuleToPostgresGranule, translateApiGranuleToPostgresGranuleWithoutNilsRemoved, translatePostgresGranuleToApiGranule, translatePostgresGranuleResultToApiGranule, } from './translate/granules';
|
|
27
27
|
export { translateApiPdrToPostgresPdr, translatePostgresPdrToApiPdr, } from './translate/pdr';
|
|
28
28
|
export { getCollectionsByGranuleIds, } from './lib/collection';
|
|
29
|
-
export {
|
|
29
|
+
export { batchDeleteExecutionFromDatabaseByCumulusCollectionId, executionArnsFromGranuleIdsAndWorkflowNames, getApiExecutionCumulusIds, getApiGranuleExecutionCumulusIdsByExecution, getExecutionInfoByGranuleCumulusId, getWorkflowNameIntersectFromGranuleIds, newestExecutionArnFromGranuleIdWorkflowName, } from './lib/execution';
|
|
30
30
|
export { getFilesAndGranuleInfoQuery, } from './lib/file';
|
|
31
31
|
export { getApiGranuleCumulusIds, getApiGranuleExecutionCumulusIds, getGranuleCollectionId, getUniqueGranuleByGranuleId, getGranuleByUniqueColumns, upsertGranuleWithExecutionJoinRecord, getGranulesByApiPropertiesQuery, getGranulesByGranuleId, getGranuleAndCollection, } from './lib/granule';
|
|
32
32
|
export { QuerySearchClient, } from './lib/QuerySearchClient';
|
|
33
|
+
export { BaseSearch, } from './search/BaseSearch';
|
|
34
|
+
export { ExecutionSearch, } from './search/ExecutionSearch';
|
|
35
|
+
export { GranuleSearch, } from './search/GranuleSearch';
|
|
36
|
+
export { StatsSearch, } from './search/StatsSearch';
|
|
37
|
+
export { CollectionSearch, } from './search/CollectionSearch';
|
|
33
38
|
export { AsyncOperationPgModel } from './models/async_operation';
|
|
34
39
|
export { BasePgModel } from './models/base';
|
|
35
40
|
export { CollectionPgModel } from './models/collection';
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.RulePgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.QuerySearchClient = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = void 0;
|
|
26
|
+
exports.newestExecutionArnFromGranuleIdWorkflowName = exports.getWorkflowNameIntersectFromGranuleIds = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = exports.getApiExecutionCumulusIds = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.batchDeleteExecutionFromDatabaseByCumulusCollectionId = exports.getCollectionsByGranuleIds = 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.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.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.CollectionSearch = exports.StatsSearch = exports.GranuleSearch = exports.ExecutionSearch = exports.BaseSearch = exports.QuerySearchClient = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getFilesAndGranuleInfoQuery = 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; } });
|
|
@@ -87,12 +87,13 @@ Object.defineProperty(exports, "translatePostgresPdrToApiPdr", { enumerable: tru
|
|
|
87
87
|
var collection_1 = require("./lib/collection");
|
|
88
88
|
Object.defineProperty(exports, "getCollectionsByGranuleIds", { enumerable: true, get: function () { return collection_1.getCollectionsByGranuleIds; } });
|
|
89
89
|
var execution_1 = require("./lib/execution");
|
|
90
|
+
Object.defineProperty(exports, "batchDeleteExecutionFromDatabaseByCumulusCollectionId", { enumerable: true, get: function () { return execution_1.batchDeleteExecutionFromDatabaseByCumulusCollectionId; } });
|
|
90
91
|
Object.defineProperty(exports, "executionArnsFromGranuleIdsAndWorkflowNames", { enumerable: true, get: function () { return execution_1.executionArnsFromGranuleIdsAndWorkflowNames; } });
|
|
91
|
-
Object.defineProperty(exports, "newestExecutionArnFromGranuleIdWorkflowName", { enumerable: true, get: function () { return execution_1.newestExecutionArnFromGranuleIdWorkflowName; } });
|
|
92
|
-
Object.defineProperty(exports, "getWorkflowNameIntersectFromGranuleIds", { enumerable: true, get: function () { return execution_1.getWorkflowNameIntersectFromGranuleIds; } });
|
|
93
92
|
Object.defineProperty(exports, "getApiExecutionCumulusIds", { enumerable: true, get: function () { return execution_1.getApiExecutionCumulusIds; } });
|
|
94
93
|
Object.defineProperty(exports, "getApiGranuleExecutionCumulusIdsByExecution", { enumerable: true, get: function () { return execution_1.getApiGranuleExecutionCumulusIdsByExecution; } });
|
|
95
94
|
Object.defineProperty(exports, "getExecutionInfoByGranuleCumulusId", { enumerable: true, get: function () { return execution_1.getExecutionInfoByGranuleCumulusId; } });
|
|
95
|
+
Object.defineProperty(exports, "getWorkflowNameIntersectFromGranuleIds", { enumerable: true, get: function () { return execution_1.getWorkflowNameIntersectFromGranuleIds; } });
|
|
96
|
+
Object.defineProperty(exports, "newestExecutionArnFromGranuleIdWorkflowName", { enumerable: true, get: function () { return execution_1.newestExecutionArnFromGranuleIdWorkflowName; } });
|
|
96
97
|
var file_2 = require("./lib/file");
|
|
97
98
|
Object.defineProperty(exports, "getFilesAndGranuleInfoQuery", { enumerable: true, get: function () { return file_2.getFilesAndGranuleInfoQuery; } });
|
|
98
99
|
var granule_1 = require("./lib/granule");
|
|
@@ -107,6 +108,16 @@ Object.defineProperty(exports, "getGranulesByGranuleId", { enumerable: true, get
|
|
|
107
108
|
Object.defineProperty(exports, "getGranuleAndCollection", { enumerable: true, get: function () { return granule_1.getGranuleAndCollection; } });
|
|
108
109
|
var QuerySearchClient_1 = require("./lib/QuerySearchClient");
|
|
109
110
|
Object.defineProperty(exports, "QuerySearchClient", { enumerable: true, get: function () { return QuerySearchClient_1.QuerySearchClient; } });
|
|
111
|
+
var BaseSearch_1 = require("./search/BaseSearch");
|
|
112
|
+
Object.defineProperty(exports, "BaseSearch", { enumerable: true, get: function () { return BaseSearch_1.BaseSearch; } });
|
|
113
|
+
var ExecutionSearch_1 = require("./search/ExecutionSearch");
|
|
114
|
+
Object.defineProperty(exports, "ExecutionSearch", { enumerable: true, get: function () { return ExecutionSearch_1.ExecutionSearch; } });
|
|
115
|
+
var GranuleSearch_1 = require("./search/GranuleSearch");
|
|
116
|
+
Object.defineProperty(exports, "GranuleSearch", { enumerable: true, get: function () { return GranuleSearch_1.GranuleSearch; } });
|
|
117
|
+
var StatsSearch_1 = require("./search/StatsSearch");
|
|
118
|
+
Object.defineProperty(exports, "StatsSearch", { enumerable: true, get: function () { return StatsSearch_1.StatsSearch; } });
|
|
119
|
+
var CollectionSearch_1 = require("./search/CollectionSearch");
|
|
120
|
+
Object.defineProperty(exports, "CollectionSearch", { enumerable: true, get: function () { return CollectionSearch_1.CollectionSearch; } });
|
|
110
121
|
var async_operation_1 = require("./models/async_operation");
|
|
111
122
|
Object.defineProperty(exports, "AsyncOperationPgModel", { enumerable: true, get: function () { return async_operation_1.AsyncOperationPgModel; } });
|
|
112
123
|
var base_1 = require("./models/base");
|
package/dist/lib/execution.d.ts
CHANGED
|
@@ -92,4 +92,9 @@ export declare const getApiExecutionCumulusIds: (knexOrTransaction: Knex | Knex.
|
|
|
92
92
|
export declare const getApiGranuleExecutionCumulusIdsByExecution: (knexOrTransaction: Knex | Knex.Transaction, executions: Array<{
|
|
93
93
|
arn: string;
|
|
94
94
|
}>, executionPgModel?: ExecutionPgModel, granulesExecutionsPgModel?: GranulesExecutionsPgModel) => Promise<Array<number>>;
|
|
95
|
+
export declare const batchDeleteExecutionFromDatabaseByCumulusCollectionId: (params: {
|
|
96
|
+
knex: Knex | Knex.Transaction;
|
|
97
|
+
collectionCumulusId: number;
|
|
98
|
+
batchSize: number;
|
|
99
|
+
}) => Promise<number>;
|
|
95
100
|
//# sourceMappingURL=execution.d.ts.map
|
package/dist/lib/execution.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getApiGranuleExecutionCumulusIdsByExecution = exports.getApiExecutionCumulusIds = exports.getWorkflowNameIntersectFromGranuleIds = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.getExecutionArnsByGranuleCumulusId = exports.getExecutionInfoByGranuleCumulusId = void 0;
|
|
3
|
+
exports.batchDeleteExecutionFromDatabaseByCumulusCollectionId = exports.getApiGranuleExecutionCumulusIdsByExecution = exports.getApiExecutionCumulusIds = exports.getWorkflowNameIntersectFromGranuleIds = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.getExecutionArnsByGranuleCumulusId = exports.getExecutionInfoByGranuleCumulusId = void 0;
|
|
4
4
|
const errors_1 = require("@cumulus/errors");
|
|
5
5
|
const execution_1 = require("../models/execution");
|
|
6
6
|
const granules_executions_1 = require("../models/granules-executions");
|
|
@@ -164,4 +164,19 @@ const getApiGranuleExecutionCumulusIdsByExecution = async (knexOrTransaction, ex
|
|
|
164
164
|
return granuleCumulusIds;
|
|
165
165
|
};
|
|
166
166
|
exports.getApiGranuleExecutionCumulusIdsByExecution = getApiGranuleExecutionCumulusIdsByExecution;
|
|
167
|
+
const batchDeleteExecutionFromDatabaseByCumulusCollectionId = async (params) => {
|
|
168
|
+
const { knex, collectionCumulusId, batchSize = 1 } = params;
|
|
169
|
+
try {
|
|
170
|
+
return await knex('executions')
|
|
171
|
+
.whereIn('cumulus_id', knex.select('cumulus_id')
|
|
172
|
+
.from('executions')
|
|
173
|
+
.where('collection_cumulus_id', collectionCumulusId)
|
|
174
|
+
.limit(batchSize))
|
|
175
|
+
.delete();
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
throw new Error(`Failed to delete from database: ${error.message}`);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
exports.batchDeleteExecutionFromDatabaseByCumulusCollectionId = batchDeleteExecutionFromDatabaseByCumulusCollectionId;
|
|
167
182
|
//# sourceMappingURL=execution.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
const up = async (knex) => {
|
|
5
|
+
await knex.raw('ALTER TABLE files ALTER COLUMN granule_cumulus_id TYPE BIGINT');
|
|
6
|
+
await knex.raw('ALTER TABLE executions ALTER COLUMN cumulus_id TYPE BIGINT, ALTER COLUMN parent_cumulus_id TYPE BIGINT');
|
|
7
|
+
await knex.raw('ALTER TABLE granules_executions ALTER COLUMN granule_cumulus_id TYPE BIGINT, ALTER COLUMN execution_cumulus_id TYPE BIGINT');
|
|
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
|
+
};
|
|
14
|
+
exports.up = up;
|
|
15
|
+
const down = async () => {
|
|
16
|
+
console.log('Warning - this migration cannot be rolled back');
|
|
17
|
+
};
|
|
18
|
+
exports.down = down;
|
|
19
|
+
exports.config = {
|
|
20
|
+
transaction: false,
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=20240125171703_update_granule_execution_cumulus_id_type.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
const up = async (knex) => {
|
|
5
|
+
await knex.raw('CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS granules_collection_cumulus_id_granule_id_unique ON granules(collection_cumulus_id, granule_id)');
|
|
6
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS granules_granule_id_index ON granules(granule_id)');
|
|
7
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS granules_provider_collection_cumulus_id_granule_id_index ON granules(provider_cumulus_id, collection_cumulus_id, granule_id)');
|
|
8
|
+
};
|
|
9
|
+
exports.up = up;
|
|
10
|
+
const down = async (knex) => {
|
|
11
|
+
await knex.raw('DROP INDEX IF EXISTS granules_collection_cumulus_id_granule_id_unique');
|
|
12
|
+
await knex.raw('DROP INDEX IF EXISTS granules_granule_id_index');
|
|
13
|
+
await knex.raw('DROP INDEX IF EXISTS granules_provider_collection_cumulus_id_granule_id_index');
|
|
14
|
+
};
|
|
15
|
+
exports.down = down;
|
|
16
|
+
exports.config = {
|
|
17
|
+
transaction: false,
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=20240126135619_granules_add_indexes.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
const addConstraintIfNotExists = async ({ knex, tableName, constraintName, constraintSql, }) => {
|
|
5
|
+
const constraintExists = await knex.raw(`
|
|
6
|
+
SELECT constraint_name
|
|
7
|
+
FROM information_schema.constraint_column_usage
|
|
8
|
+
WHERE constraint_name = ?
|
|
9
|
+
AND table_name = ?
|
|
10
|
+
`, [constraintName, tableName]);
|
|
11
|
+
if (constraintExists.rows.length === 0) {
|
|
12
|
+
await knex.raw(`
|
|
13
|
+
ALTER TABLE ${tableName} ${constraintSql}
|
|
14
|
+
`);
|
|
15
|
+
console.log(`Constraint ${constraintName} added to table ${tableName}`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.log(`Constraint ${constraintName} already exists on table ${tableName}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const up = async (knex) => {
|
|
22
|
+
// ALTER TABLE granules ADD UNIQUE USING INDEX granules_collection_cumulus_id_granule_id_unique
|
|
23
|
+
await addConstraintIfNotExists({
|
|
24
|
+
knex,
|
|
25
|
+
tableName: 'granules',
|
|
26
|
+
constraintName: 'granules_collection_cumulus_id_granule_id_unique',
|
|
27
|
+
constraintSql: 'ADD UNIQUE USING INDEX granules_collection_cumulus_id_granule_id_unique',
|
|
28
|
+
});
|
|
29
|
+
await knex.raw('ALTER TABLE granules DROP constraint IF EXISTS granules_granule_id_collection_cumulus_id_unique');
|
|
30
|
+
};
|
|
31
|
+
exports.up = up;
|
|
32
|
+
const down = async (knex) => {
|
|
33
|
+
// ALTER TABLE granules ADD CONSTRAINT
|
|
34
|
+
// granules_granule_id_collection_cumulus_id_unique UNIQUE (granule_id, collection_cumulus_id)
|
|
35
|
+
await addConstraintIfNotExists({
|
|
36
|
+
knex,
|
|
37
|
+
tableName: 'granules',
|
|
38
|
+
constraintName: 'granules_granule_id_collection_cumulus_id_unique',
|
|
39
|
+
constraintSql: 'ADD CONSTRAINT granules_granule_id_collection_cumulus_id_unique UNIQUE (granule_id, collection_cumulus_id)',
|
|
40
|
+
});
|
|
41
|
+
await knex.raw('ALTER TABLE granules DROP CONSTRAINT IF EXISTS granules_collection_cumulus_id_granule_id_unique');
|
|
42
|
+
};
|
|
43
|
+
exports.down = down;
|
|
44
|
+
//# sourceMappingURL=20240126165019_granules_update_constraints.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
const formatAlterTableEnumSql = (tableName, columnName, enums) => {
|
|
5
|
+
const constraintName = `${tableName}_${columnName}_check`;
|
|
6
|
+
return [
|
|
7
|
+
`ALTER TABLE ${tableName}`,
|
|
8
|
+
`DROP CONSTRAINT IF EXISTS ${constraintName};`,
|
|
9
|
+
`ALTER TABLE ${tableName} ADD CONSTRAINT ${constraintName} CHECK (${columnName} = ANY (ARRAY['${enums.join("'::text, '")}'::text]));`,
|
|
10
|
+
].join('\n');
|
|
11
|
+
};
|
|
12
|
+
const up = async (knex) => {
|
|
13
|
+
await knex.raw(formatAlterTableEnumSql('async_operations', 'operation_type', [
|
|
14
|
+
'Bulk Granule Delete',
|
|
15
|
+
'Bulk Granule Reingest',
|
|
16
|
+
'Bulk Granules',
|
|
17
|
+
'Bulk Execution Delete',
|
|
18
|
+
'Data Migration',
|
|
19
|
+
'Dead-Letter Processing',
|
|
20
|
+
'DLA Migration',
|
|
21
|
+
'ES Index',
|
|
22
|
+
'Kinesis Replay',
|
|
23
|
+
'Reconciliation Report',
|
|
24
|
+
'SQS Replay',
|
|
25
|
+
]));
|
|
26
|
+
};
|
|
27
|
+
exports.up = up;
|
|
28
|
+
const down = async (knex) => {
|
|
29
|
+
await knex.raw(formatAlterTableEnumSql('async_operations', 'operation_type', [
|
|
30
|
+
'ES Index',
|
|
31
|
+
'Bulk Granules',
|
|
32
|
+
'Bulk Granule Reingest',
|
|
33
|
+
'Bulk Granule Delete',
|
|
34
|
+
'Dead-Letter Processing',
|
|
35
|
+
'DLA Migration',
|
|
36
|
+
'Kinesis Replay',
|
|
37
|
+
'Reconciliation Report',
|
|
38
|
+
'Data Migration',
|
|
39
|
+
'SQS Replay',
|
|
40
|
+
]));
|
|
41
|
+
};
|
|
42
|
+
exports.down = down;
|
|
43
|
+
//# sourceMappingURL=20240606060726_alter_async_operations_add_operation_type_bulk_execution_delete.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
const up = async (knex) => {
|
|
5
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS executions_parent_cumulus_id_index ON executions(parent_cumulus_id)');
|
|
6
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS executions_collection_cumulus_id_index ON executions(collection_cumulus_id)');
|
|
7
|
+
};
|
|
8
|
+
exports.up = up;
|
|
9
|
+
const down = async (knex) => {
|
|
10
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS executions_parent_cumulus_id_index');
|
|
11
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS executions_collection_cumulus_id_index');
|
|
12
|
+
};
|
|
13
|
+
exports.down = down;
|
|
14
|
+
exports.config = {
|
|
15
|
+
transaction: false,
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=20240613174614_add_execution_parent_and_collection_indexes.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
const up = async (knex) => {
|
|
5
|
+
await knex.raw('ALTER TABLE executions DROP CONSTRAINT IF EXISTS executions_parent_cumulus_id_foreign');
|
|
6
|
+
await knex.raw('ALTER TABLE executions ADD CONSTRAINT executions_parent_cumulus_id_foreign FOREIGN KEY (parent_cumulus_id) REFERENCES executions(cumulus_id) ON DELETE SET NULL');
|
|
7
|
+
};
|
|
8
|
+
exports.up = up;
|
|
9
|
+
const down = async (knex) => {
|
|
10
|
+
await knex.raw('ALTER TABLE executions DROP CONSTRAINT IF EXISTS executions_parent_cumulus_id_foreign');
|
|
11
|
+
await knex.raw('ALTER TABLE executions ADD CONSTRAINT executions_parent_cumulus_id_foreign FOREIGN KEY (parent_cumulus_id) REFERENCES executions(cumulus_id)');
|
|
12
|
+
};
|
|
13
|
+
exports.down = down;
|
|
14
|
+
//# sourceMappingURL=20240617204826_update_executions_deletion_constraint.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.down = exports.up = void 0;
|
|
4
|
+
const up = async (knex) => {
|
|
5
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS async_operations_updated_at_index ON async_operations(updated_at)');
|
|
6
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS async_operations_status_operation_type_cumulus_id_index ON async_operations(status, operation_type, cumulus_id)');
|
|
7
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS collections_updated_at_index ON collections(updated_at)');
|
|
8
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS executions_updated_at_index ON executions(updated_at)');
|
|
9
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS executions_status_collection_cumulus_id_index ON executions(status, collection_cumulus_id, cumulus_id)');
|
|
10
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS files_updated_at_index ON files(updated_at)');
|
|
11
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS granules_updated_at_index ON granules(updated_at)');
|
|
12
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS granules_coll_status_processendtime_cumulus_id_index ON granules(collection_cumulus_id, status, processing_end_date_time, cumulus_id)');
|
|
13
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS granules_status_provider_collection_cumulus_id_index ON granules(status, provider_cumulus_id, collection_cumulus_id, cumulus_id)');
|
|
14
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS pdrs_updated_at_index ON pdrs(updated_at)');
|
|
15
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS pdrs_status_provider_collection_cumulus_id_index ON pdrs(status, provider_cumulus_id, collection_cumulus_id, cumulus_id)');
|
|
16
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS pdrs_execution_cumulus_id_index ON pdrs(execution_cumulus_id)');
|
|
17
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS pdrs_coll_status_cumulus_id_index ON pdrs(collection_cumulus_id, status, cumulus_id)');
|
|
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
|
+
await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS providers_updated_at_index ON providers(updated_at)');
|
|
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
|
+
};
|
|
30
|
+
exports.up = up;
|
|
31
|
+
const down = async (knex) => {
|
|
32
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS async_operations_updated_at_index');
|
|
33
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS async_operations_status_operation_type_cumulus_id_index');
|
|
34
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS collections_updated_at_index');
|
|
35
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS executions_updated_at_index');
|
|
36
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS executions_status_collection_cumulus_id_index');
|
|
37
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS files_updated_at_index');
|
|
38
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS granules_updated_at_index');
|
|
39
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS granules_coll_status_processendtime_cumulus_id_index');
|
|
40
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS granules_status_provider_collection_cumulus_id_index');
|
|
41
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS pdrs_updated_at_index');
|
|
42
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS pdrs_status_provider_collection_cumulus_id_index');
|
|
43
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS pdrs_execution_cumulus_id_index');
|
|
44
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS pdrs_coll_status_cumulus_id_index');
|
|
45
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS pdrs_provider_collection_cumulus_id_name_index');
|
|
46
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS providers_updated_at_index');
|
|
47
|
+
await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS rules_updated_at_index');
|
|
48
|
+
};
|
|
49
|
+
exports.down = down;
|
|
50
|
+
exports.config = {
|
|
51
|
+
transaction: false,
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=20240728101230_add_table_indexes.js.map
|
|
@@ -16,12 +16,12 @@ declare class ExecutionPgModel extends BasePgModel<PostgresExecution, PostgresEx
|
|
|
16
16
|
* @param {Object} [params] - Optional object with addition params for query
|
|
17
17
|
* @param {number} [params.limit] - number of records to be returned
|
|
18
18
|
* @param {number} [params.offset] - record offset
|
|
19
|
-
* @returns
|
|
19
|
+
* @returns An array of executions
|
|
20
20
|
*/
|
|
21
21
|
searchByCumulusIds(knexOrTrx: Knex | Knex.Transaction, executionCumulusIds: Array<number> | number, params: {
|
|
22
22
|
limit: number;
|
|
23
23
|
offset: number;
|
|
24
|
-
}): Promise<Array<
|
|
24
|
+
}): Promise<Array<PostgresExecutionRecord>>;
|
|
25
25
|
}
|
|
26
26
|
export { ExecutionPgModel };
|
|
27
27
|
//# sourceMappingURL=execution.d.ts.map
|
package/dist/models/execution.js
CHANGED
|
@@ -42,7 +42,7 @@ class ExecutionPgModel extends base_1.BasePgModel {
|
|
|
42
42
|
* @param {Object} [params] - Optional object with addition params for query
|
|
43
43
|
* @param {number} [params.limit] - number of records to be returned
|
|
44
44
|
* @param {number} [params.offset] - record offset
|
|
45
|
-
* @returns
|
|
45
|
+
* @returns An array of executions
|
|
46
46
|
*/
|
|
47
47
|
async searchByCumulusIds(knexOrTrx, executionCumulusIds, params) {
|
|
48
48
|
const { limit, offset, ...sortQueries } = params || {};
|