@cumulus/db 21.0.1 → 21.2.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/migrations/20250922190412_add_bulk_archive_types_to_async_op_type_enum.d.ts +4 -0
- package/dist/migrations/20250922190412_add_bulk_archive_types_to_async_op_type_enum.js +48 -0
- package/dist/models/execution.d.ts +14 -0
- package/dist/models/execution.js +21 -0
- package/dist/models/file.d.ts +1 -9
- package/dist/models/file.js +5 -2
- package/dist/models/granule.d.ts +14 -0
- package/dist/models/granule.js +21 -0
- package/package.json +8 -8
|
@@ -0,0 +1,48 @@
|
|
|
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 Execution Archive',
|
|
15
|
+
'Bulk Execution Delete',
|
|
16
|
+
'Bulk Granules',
|
|
17
|
+
'Bulk Granule Archive',
|
|
18
|
+
'Bulk Granule Delete',
|
|
19
|
+
'Bulk Granule Reingest',
|
|
20
|
+
'Data Migration',
|
|
21
|
+
'Dead-Letter Processing',
|
|
22
|
+
'DLA Migration',
|
|
23
|
+
'ES Index',
|
|
24
|
+
'Kinesis Replay',
|
|
25
|
+
'Migration Count Report',
|
|
26
|
+
'Reconciliation Report',
|
|
27
|
+
'SQS Replay',
|
|
28
|
+
]));
|
|
29
|
+
};
|
|
30
|
+
exports.up = up;
|
|
31
|
+
const down = async (knex) => {
|
|
32
|
+
await knex.raw(formatAlterTableEnumSql('async_operations', 'operation_type', [
|
|
33
|
+
'Bulk Execution Delete',
|
|
34
|
+
'Bulk Granules',
|
|
35
|
+
'Bulk Granule Delete',
|
|
36
|
+
'Bulk Granule Reingest',
|
|
37
|
+
'Data Migration',
|
|
38
|
+
'Dead-Letter Processing',
|
|
39
|
+
'DLA Migration',
|
|
40
|
+
'ES Index',
|
|
41
|
+
'Kinesis Replay',
|
|
42
|
+
'Migration Count Report',
|
|
43
|
+
'Reconciliation Report',
|
|
44
|
+
'SQS Replay',
|
|
45
|
+
]));
|
|
46
|
+
};
|
|
47
|
+
exports.down = down;
|
|
48
|
+
//# sourceMappingURL=20250922190412_add_bulk_archive_types_to_async_op_type_enum.js.map
|
|
@@ -22,6 +22,20 @@ declare class ExecutionPgModel extends BasePgModel<PostgresExecution, PostgresEx
|
|
|
22
22
|
limit: number;
|
|
23
23
|
offset: number;
|
|
24
24
|
}): Promise<Array<PostgresExecutionRecord>>;
|
|
25
|
+
/**
|
|
26
|
+
* update executions to set archived=true within date range
|
|
27
|
+
*
|
|
28
|
+
* @param {Knex | Knex.Transaction} knexOrTrx -
|
|
29
|
+
* DB client or transaction
|
|
30
|
+
* @param {Object} [params] - Optional object with addition params for query
|
|
31
|
+
* @param {number} [params.limit] - number of records to be returned
|
|
32
|
+
* @param {string} [params.expirationDate] - record offset
|
|
33
|
+
* @returns {Promise<number>} number of records actually updated
|
|
34
|
+
*/
|
|
35
|
+
bulkArchive(knexOrTrx: Knex | Knex.Transaction, params: {
|
|
36
|
+
limit: number;
|
|
37
|
+
expirationDate: string;
|
|
38
|
+
}): Promise<number>;
|
|
25
39
|
}
|
|
26
40
|
export { ExecutionPgModel };
|
|
27
41
|
//# sourceMappingURL=execution.d.ts.map
|
package/dist/models/execution.js
CHANGED
|
@@ -65,6 +65,27 @@ class ExecutionPgModel extends base_1.BasePgModel {
|
|
|
65
65
|
});
|
|
66
66
|
return executions;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* update executions to set archived=true within date range
|
|
70
|
+
*
|
|
71
|
+
* @param {Knex | Knex.Transaction} knexOrTrx -
|
|
72
|
+
* DB client or transaction
|
|
73
|
+
* @param {Object} [params] - Optional object with addition params for query
|
|
74
|
+
* @param {number} [params.limit] - number of records to be returned
|
|
75
|
+
* @param {string} [params.expirationDate] - record offset
|
|
76
|
+
* @returns {Promise<number>} number of records actually updated
|
|
77
|
+
*/
|
|
78
|
+
async bulkArchive(knexOrTrx, params) {
|
|
79
|
+
const { limit, expirationDate } = params;
|
|
80
|
+
const subQuery = knexOrTrx(this.tableName)
|
|
81
|
+
.select('cumulus_id')
|
|
82
|
+
.where('updated_at', '<', expirationDate)
|
|
83
|
+
.where('archived', false)
|
|
84
|
+
.limit(limit);
|
|
85
|
+
return await knexOrTrx(this.tableName)
|
|
86
|
+
.update({ archived: true })
|
|
87
|
+
.whereIn('cumulus_id', subQuery);
|
|
88
|
+
}
|
|
68
89
|
}
|
|
69
90
|
exports.ExecutionPgModel = ExecutionPgModel;
|
|
70
91
|
ExecutionPgModel.nonActiveStatuses = ['completed', 'failed', 'unknown'];
|
package/dist/models/file.d.ts
CHANGED
|
@@ -3,15 +3,7 @@ import { BasePgModel } from './base';
|
|
|
3
3
|
import { PostgresFile, PostgresFileRecord } from '../types/file';
|
|
4
4
|
declare class FilePgModel extends BasePgModel<PostgresFile, PostgresFileRecord> {
|
|
5
5
|
constructor();
|
|
6
|
-
upsert(knexOrTrx: Knex | Knex.Transaction,
|
|
7
|
-
_base: any;
|
|
8
|
-
_hasSelection: false;
|
|
9
|
-
_keys: never;
|
|
10
|
-
_aliases: {};
|
|
11
|
-
_single: false;
|
|
12
|
-
_intersectProps: {};
|
|
13
|
-
_unionProps: never;
|
|
14
|
-
}[]>;
|
|
6
|
+
upsert(knexOrTrx: Knex | Knex.Transaction, input: PostgresFile | PostgresFile[]): Promise<PostgresFileRecord[]>;
|
|
15
7
|
/**
|
|
16
8
|
* Retrieves all files for all granules given
|
|
17
9
|
*/
|
package/dist/models/file.js
CHANGED
|
@@ -9,9 +9,12 @@ class FilePgModel extends base_1.BasePgModel {
|
|
|
9
9
|
tableName: tables_1.TableNames.files,
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
upsert(knexOrTrx,
|
|
12
|
+
upsert(knexOrTrx, input) {
|
|
13
|
+
const files = Array.isArray(input) ? input : [input];
|
|
14
|
+
if (files.length === 0)
|
|
15
|
+
return Promise.resolve([]);
|
|
13
16
|
return knexOrTrx(this.tableName)
|
|
14
|
-
.insert(
|
|
17
|
+
.insert(files)
|
|
15
18
|
.onConflict(['bucket', 'key'])
|
|
16
19
|
.merge()
|
|
17
20
|
.returning('*');
|
package/dist/models/granule.d.ts
CHANGED
|
@@ -69,6 +69,20 @@ export default class GranulePgModel extends BasePgModel<PostgresGranule, Postgre
|
|
|
69
69
|
limit: number;
|
|
70
70
|
offset: number;
|
|
71
71
|
}): Promise<Array<PostgresGranuleRecord>>;
|
|
72
|
+
/**
|
|
73
|
+
* update granules to set archived=true within date range
|
|
74
|
+
*
|
|
75
|
+
* @param {Knex | Knex.Transaction} knexOrTrx -
|
|
76
|
+
* DB client or transaction
|
|
77
|
+
* @param {Object} [params] - Optional object with addition params for query
|
|
78
|
+
* @param {number} [params.limit] - number of records to be returned
|
|
79
|
+
* @param {string} [params.expirationDate] - record offset
|
|
80
|
+
* @returns {Promise<number>} number of records actually updated
|
|
81
|
+
*/
|
|
82
|
+
bulkArchive(knexOrTrx: Knex | Knex.Transaction, params: {
|
|
83
|
+
limit: number;
|
|
84
|
+
expirationDate: string;
|
|
85
|
+
}): Promise<number>;
|
|
72
86
|
}
|
|
73
87
|
export { GranulePgModel };
|
|
74
88
|
//# sourceMappingURL=granule.d.ts.map
|
package/dist/models/granule.js
CHANGED
|
@@ -154,6 +154,27 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
154
154
|
});
|
|
155
155
|
return granules;
|
|
156
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* update granules to set archived=true within date range
|
|
159
|
+
*
|
|
160
|
+
* @param {Knex | Knex.Transaction} knexOrTrx -
|
|
161
|
+
* DB client or transaction
|
|
162
|
+
* @param {Object} [params] - Optional object with addition params for query
|
|
163
|
+
* @param {number} [params.limit] - number of records to be returned
|
|
164
|
+
* @param {string} [params.expirationDate] - record offset
|
|
165
|
+
* @returns {Promise<number>} number of records actually updated
|
|
166
|
+
*/
|
|
167
|
+
async bulkArchive(knexOrTrx, params) {
|
|
168
|
+
const { limit, expirationDate } = params;
|
|
169
|
+
const subQuery = knexOrTrx(this.tableName)
|
|
170
|
+
.select('cumulus_id')
|
|
171
|
+
.where('updated_at', '<', expirationDate)
|
|
172
|
+
.where('archived', false)
|
|
173
|
+
.limit(limit);
|
|
174
|
+
return await knexOrTrx(this.tableName)
|
|
175
|
+
.update({ archived: true })
|
|
176
|
+
.whereIn('cumulus_id', subQuery);
|
|
177
|
+
}
|
|
157
178
|
}
|
|
158
179
|
exports.default = GranulePgModel;
|
|
159
180
|
exports.GranulePgModel = GranulePgModel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/db",
|
|
3
|
-
"version": "21.0
|
|
3
|
+
"version": "21.2.0",
|
|
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": "21.0
|
|
37
|
-
"@cumulus/common": "21.0
|
|
38
|
-
"@cumulus/errors": "21.0
|
|
39
|
-
"@cumulus/logger": "21.0
|
|
40
|
-
"@cumulus/message": "21.0
|
|
41
|
-
"@cumulus/types": "21.0
|
|
36
|
+
"@cumulus/aws-client": "21.2.0",
|
|
37
|
+
"@cumulus/common": "21.2.0",
|
|
38
|
+
"@cumulus/errors": "21.2.0",
|
|
39
|
+
"@cumulus/logger": "21.2.0",
|
|
40
|
+
"@cumulus/message": "21.2.0",
|
|
41
|
+
"@cumulus/types": "21.2.0",
|
|
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": "696befd260527f74a8a5bfb92f9511b455a23388"
|
|
54
54
|
}
|