@cumulus/db 10.0.0-beta.0 → 10.1.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/dist/config.d.ts +1 -0
- package/dist/config.js +4 -2
- package/dist/connection.js +29 -8
- package/dist/migrations/20220126172008_files_granule_id_index.d.ts +4 -0
- package/dist/migrations/20220126172008_files_granule_id_index.js +16 -0
- package/dist/models/base.d.ts +2 -2
- package/dist/models/base.js +2 -2
- package/dist/models/execution.d.ts +2 -2
- package/dist/models/execution.js +2 -2
- package/dist/translate/executions.js +2 -2
- package/package.json +9 -9
package/dist/config.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const localStackConnectionEnv: {
|
|
|
8
8
|
PG_DATABASE: string;
|
|
9
9
|
PG_PORT: string;
|
|
10
10
|
};
|
|
11
|
+
export declare const isKnexDebugEnabled: (env?: NodeJS.ProcessEnv) => boolean;
|
|
11
12
|
export declare const getSecretConnectionConfig: (SecretId: string, secretsManager: AWS.SecretsManager) => Promise<Knex.PgConnectionConfig>;
|
|
12
13
|
export declare const getConnectionConfigEnv: (env: NodeJS.ProcessEnv) => Knex.PgConnectionConfig;
|
|
13
14
|
/**
|
package/dist/config.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.getKnexConfig = exports.getConnectionConfig = exports.getConnectionConfigEnv = exports.getSecretConnectionConfig = exports.localStackConnectionEnv = void 0;
|
|
6
|
+
exports.getKnexConfig = exports.getConnectionConfig = exports.getConnectionConfigEnv = exports.getSecretConnectionConfig = exports.isKnexDebugEnabled = exports.localStackConnectionEnv = void 0;
|
|
7
7
|
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
8
8
|
const common_1 = require("@cumulus/common");
|
|
9
9
|
exports.localStackConnectionEnv = {
|
|
@@ -13,6 +13,8 @@ exports.localStackConnectionEnv = {
|
|
|
13
13
|
PG_DATABASE: 'postgres',
|
|
14
14
|
PG_PORT: '5432',
|
|
15
15
|
};
|
|
16
|
+
const isKnexDebugEnabled = (env = {}) => env.KNEX_DEBUG === 'true';
|
|
17
|
+
exports.isKnexDebugEnabled = isKnexDebugEnabled;
|
|
16
18
|
const getSecretConnectionConfig = async (SecretId, secretsManager) => {
|
|
17
19
|
var _a;
|
|
18
20
|
const response = await secretsManager.getSecretValue({ SecretId }).promise();
|
|
@@ -110,7 +112,7 @@ const getKnexConfig = async ({ env = process.env, secretsManager = new aws_sdk_1
|
|
|
110
112
|
const knexConfig = {
|
|
111
113
|
client: 'pg',
|
|
112
114
|
connection: await (0, exports.getConnectionConfig)({ env, secretsManager }),
|
|
113
|
-
debug: env
|
|
115
|
+
debug: (0, exports.isKnexDebugEnabled)(env),
|
|
114
116
|
asyncStackTraces: env.KNEX_ASYNC_STACK_TRACES === 'true',
|
|
115
117
|
pool: {
|
|
116
118
|
min: 0,
|
package/dist/connection.js
CHANGED
|
@@ -44,16 +44,37 @@ const log = new logger_1.default({ sender: '@cumulus/db/connection' });
|
|
|
44
44
|
* @returns {Promise<Knex>} a Knex configuration object that has returned at least one query
|
|
45
45
|
*/
|
|
46
46
|
const getKnexClient = async ({ env = process.env, secretsManager = new aws_sdk_1.default.SecretsManager(), knexLogger = log, } = {}) => {
|
|
47
|
+
if ((0, config_1.isKnexDebugEnabled)(env)) {
|
|
48
|
+
knexLogger.info('Initializing connection pool...');
|
|
49
|
+
}
|
|
47
50
|
const knexConfig = await (0, config_1.getKnexConfig)({ env, secretsManager });
|
|
48
51
|
const knexClient = (0, knex_1.knex)(knexConfig);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
if ((0, config_1.isKnexDebugEnabled)(env)) {
|
|
53
|
+
//@ts-ignore
|
|
54
|
+
// context is an internal object that isn't typed
|
|
55
|
+
// this is needed to force tarn to log per-retry failures
|
|
56
|
+
// and allow propagateCreateError to be set `false`
|
|
57
|
+
knexClient.context.client.pool.on('createFail', (_, error) => {
|
|
58
|
+
knexLogger.warn('knex failed on attempted connection', error);
|
|
59
|
+
throw error;
|
|
60
|
+
});
|
|
61
|
+
//@ts-ignore
|
|
62
|
+
knexClient.context.client.pool.on('createSuccess', (_, resource) => {
|
|
63
|
+
knexLogger.info(`added connection to pool: ${JSON.stringify(resource)}`);
|
|
64
|
+
});
|
|
65
|
+
//@ts-ignore
|
|
66
|
+
knexClient.context.client.pool.on('acquireSuccess', (_, resource) => {
|
|
67
|
+
knexLogger.info(`acquired connection from pool: ${JSON.stringify(resource)}`);
|
|
68
|
+
});
|
|
69
|
+
//@ts-ignore
|
|
70
|
+
knexClient.context.client.pool.on('release', (resource) => {
|
|
71
|
+
knexLogger.info(`released connection from pool: ${JSON.stringify(resource)}`);
|
|
72
|
+
});
|
|
73
|
+
//@ts-ignore
|
|
74
|
+
knexClient.context.client.pool.on('poolDestroySuccess', () => {
|
|
75
|
+
knexLogger.info('pool is destroyed');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
57
78
|
return knexClient;
|
|
58
79
|
};
|
|
59
80
|
exports.getKnexClient = getKnexClient;
|
|
@@ -0,0 +1,16 @@
|
|
|
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.schema.table('files', (table) => {
|
|
6
|
+
table.index('granule_cumulus_id');
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
exports.up = up;
|
|
10
|
+
const down = async (knex) => {
|
|
11
|
+
await knex.schema.table('files', (table) => {
|
|
12
|
+
table.dropIndex('granule_cumulus_id');
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.down = down;
|
|
16
|
+
//# sourceMappingURL=20220126172008_files_granule_id_index.js.map
|
package/dist/models/base.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare class BasePgModel<ItemType, RecordType extends {
|
|
|
22
22
|
* Fetches multiple items from Postgres
|
|
23
23
|
*
|
|
24
24
|
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {Object} params - An object or any portion of an object of type RecordType
|
|
26
26
|
* @returns {Promise<RecordType[]>} List of returned records
|
|
27
27
|
*/
|
|
28
28
|
search(knexOrTransaction: Knex | Knex.Transaction, params: Partial<RecordType>): Promise<RecordType[]>;
|
|
@@ -41,7 +41,7 @@ declare class BasePgModel<ItemType, RecordType extends {
|
|
|
41
41
|
*
|
|
42
42
|
* @param {Knex | Knex.Transaction} knexOrTransaction -
|
|
43
43
|
* DB client or transaction
|
|
44
|
-
* @param {Array<
|
|
44
|
+
* @param {Array<string>} columnNames - column names for whereIn query
|
|
45
45
|
* @param {Array<string>} values - record values for whereIn query
|
|
46
46
|
* @returns {Promise<Array<number>>} An array of cumulus_ids for the returned records
|
|
47
47
|
*/
|
package/dist/models/base.js
CHANGED
|
@@ -40,7 +40,7 @@ class BasePgModel {
|
|
|
40
40
|
* Fetches multiple items from Postgres
|
|
41
41
|
*
|
|
42
42
|
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
43
|
-
* @param {
|
|
43
|
+
* @param {Object} params - An object or any portion of an object of type RecordType
|
|
44
44
|
* @returns {Promise<RecordType[]>} List of returned records
|
|
45
45
|
*/
|
|
46
46
|
async search(knexOrTransaction, params) {
|
|
@@ -72,7 +72,7 @@ class BasePgModel {
|
|
|
72
72
|
*
|
|
73
73
|
* @param {Knex | Knex.Transaction} knexOrTransaction -
|
|
74
74
|
* DB client or transaction
|
|
75
|
-
* @param {Array<
|
|
75
|
+
* @param {Array<string>} columnNames - column names for whereIn query
|
|
76
76
|
* @param {Array<string>} values - record values for whereIn query
|
|
77
77
|
* @returns {Promise<Array<number>>} An array of cumulus_ids for the returned records
|
|
78
78
|
*/
|
|
@@ -10,11 +10,11 @@ declare class ExecutionPgModel extends BasePgModel<PostgresExecution, PostgresEx
|
|
|
10
10
|
* @param {Knex | Knex.Transaction} knexOrTrx -
|
|
11
11
|
* DB client or transaction
|
|
12
12
|
* @param {Array<number>} executionCumulusIds -
|
|
13
|
-
* single execution cumulus_id or array of
|
|
13
|
+
* single execution cumulus_id or array of execution cumulus_ids
|
|
14
14
|
* @param {Object} [params] - Optional object with addition params for query
|
|
15
15
|
* @param {number} [params.limit] - number of records to be returned
|
|
16
16
|
* @param {number} [params.offset] - record offset
|
|
17
|
-
* @returns {Promise<Array<number>>} An array of
|
|
17
|
+
* @returns {Promise<Array<number>>} An array of executions
|
|
18
18
|
*/
|
|
19
19
|
searchByCumulusIds(knexOrTrx: Knex | Knex.Transaction, executionCumulusIds: Array<number> | number, params: {
|
|
20
20
|
limit: number;
|
package/dist/models/execution.js
CHANGED
|
@@ -35,11 +35,11 @@ class ExecutionPgModel extends base_1.BasePgModel {
|
|
|
35
35
|
* @param {Knex | Knex.Transaction} knexOrTrx -
|
|
36
36
|
* DB client or transaction
|
|
37
37
|
* @param {Array<number>} executionCumulusIds -
|
|
38
|
-
* single execution cumulus_id or array of
|
|
38
|
+
* single execution cumulus_id or array of execution cumulus_ids
|
|
39
39
|
* @param {Object} [params] - Optional object with addition params for query
|
|
40
40
|
* @param {number} [params.limit] - number of records to be returned
|
|
41
41
|
* @param {number} [params.offset] - record offset
|
|
42
|
-
* @returns {Promise<Array<number>>} An array of
|
|
42
|
+
* @returns {Promise<Array<number>>} An array of executions
|
|
43
43
|
*/
|
|
44
44
|
async searchByCumulusIds(knexOrTrx, executionCumulusIds, params) {
|
|
45
45
|
const { limit, offset, ...sortQueries } = params || {};
|
|
@@ -95,8 +95,8 @@ const translateApiExecutionToPostgresExecution = async (dynamoRecord, knex, coll
|
|
|
95
95
|
updated_at: dynamoRecord.updatedAt ? new Date(dynamoRecord.updatedAt) : undefined,
|
|
96
96
|
};
|
|
97
97
|
if (dynamoRecord.collectionId !== undefined) {
|
|
98
|
-
const
|
|
99
|
-
translatedRecord.collection_cumulus_id = await collectionPgModel.getRecordCumulusId(knex, { name
|
|
98
|
+
const { name, version } = (0, Collections_1.deconstructCollectionId)(dynamoRecord.collectionId);
|
|
99
|
+
translatedRecord.collection_cumulus_id = await collectionPgModel.getRecordCumulusId(knex, { name, version });
|
|
100
100
|
}
|
|
101
101
|
// If we have a parentArn, try a lookup in Postgres. If there's a match, set the parent_cumulus_id
|
|
102
102
|
if (dynamoRecord.parentArn !== undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/db",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Utilities for working with the Cumulus DB",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"node": ">=12.18.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@cumulus/aws-client": "10.
|
|
33
|
-
"@cumulus/common": "10.
|
|
34
|
-
"@cumulus/errors": "10.
|
|
35
|
-
"@cumulus/logger": "10.
|
|
36
|
-
"@cumulus/message": "10.
|
|
37
|
-
"@cumulus/types": "10.
|
|
32
|
+
"@cumulus/aws-client": "10.1.0",
|
|
33
|
+
"@cumulus/common": "10.1.0",
|
|
34
|
+
"@cumulus/errors": "10.1.0",
|
|
35
|
+
"@cumulus/logger": "10.1.0",
|
|
36
|
+
"@cumulus/message": "10.1.0",
|
|
37
|
+
"@cumulus/types": "10.1.0",
|
|
38
38
|
"crypto-random-string": "^3.2.0",
|
|
39
39
|
"is-valid-hostname": "0.0.1",
|
|
40
|
-
"knex": "0.95.
|
|
40
|
+
"knex": "0.95.15",
|
|
41
41
|
"lodash": "^4.17.20",
|
|
42
42
|
"pg": "^8.3.0",
|
|
43
43
|
"snake-camel": "^1.0.6",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/uuid": "^8.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "765ba4733ec97540e28cd64dac702eea3b96c654"
|
|
50
50
|
}
|