@cumulus/db 18.3.2 → 18.4.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 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,7 +26,7 @@ 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 { executionArnsFromGranuleIdsAndWorkflowNames, newestExecutionArnFromGranuleIdWorkflowName, getWorkflowNameIntersectFromGranuleIds, getApiExecutionCumulusIds, getApiGranuleExecutionCumulusIdsByExecution, getExecutionInfoByGranuleCumulusId, } from './lib/execution';
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';
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.getFilesAndGranuleInfoQuery = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = exports.getApiExecutionCumulusIds = exports.getWorkflowNameIntersectFromGranuleIds = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.executionArnsFromGranuleIdsAndWorkflowNames = 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.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.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");
@@ -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
@@ -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,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare const up: (knex: Knex) => Promise<void>;
3
+ export declare const down: () => Promise<void>;
4
+ //# sourceMappingURL=20240125171703_update_granule_execution_cumulus_id_type.d.ts.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,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare const up: (knex: Knex) => Promise<void>;
3
+ export declare const down: (knex: Knex) => Promise<void>;
4
+ //# sourceMappingURL=20240126135619_granules_add_indexes.d.ts.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,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare const up: (knex: Knex) => Promise<void>;
3
+ export declare const down: (knex: Knex) => Promise<void>;
4
+ //# sourceMappingURL=20240126165019_granules_update_constraints.d.ts.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,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare const up: (knex: Knex) => Promise<void>;
3
+ export declare const down: (knex: Knex) => Promise<void>;
4
+ //# sourceMappingURL=20240606060726_alter_async_operations_add_operation_type_bulk_execution_delete.d.ts.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,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare const up: (knex: Knex) => Promise<void>;
3
+ export declare const down: (knex: Knex) => Promise<void>;
4
+ //# sourceMappingURL=20240613174614_add_execution_parent_and_collection_indexes.d.ts.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,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare const up: (knex: Knex) => Promise<void>;
3
+ export declare const down: (knex: Knex) => Promise<void>;
4
+ //# sourceMappingURL=20240617204826_update_executions_deletion_constraint.d.ts.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
@@ -25,7 +25,7 @@ import { PostgresProviderRecord } from '../types/provider';
25
25
  export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, collectionPgRecord, knexOrTransaction, providerPgRecord, collectionPgModel, pdrPgModel, providerPgModel, filePgModel, }: {
26
26
  granulePgRecord: PostgresGranuleRecord;
27
27
  knexOrTransaction: Knex | Knex.Transaction;
28
- collectionPgRecord?: Pick<PostgresCollectionRecord, "version" | "name" | "cumulus_id"> | undefined;
28
+ collectionPgRecord?: Pick<PostgresCollectionRecord, "cumulus_id" | "version" | "name"> | undefined;
29
29
  providerPgRecord?: Pick<PostgresProviderRecord, "name"> | undefined;
30
30
  collectionPgModel?: CollectionPgModel | undefined;
31
31
  pdrPgModel?: PdrPgModel | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/db",
3
- "version": "18.3.2",
3
+ "version": "18.4.0",
4
4
  "description": "Utilities for working with the Cumulus DB",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -32,13 +32,13 @@
32
32
  "node": ">=20.12.2"
33
33
  },
34
34
  "dependencies": {
35
- "@aws-sdk/client-secrets-manager": "^3.447.0",
36
- "@cumulus/aws-client": "18.3.2",
37
- "@cumulus/common": "18.3.2",
38
- "@cumulus/errors": "18.3.2",
39
- "@cumulus/logger": "18.3.2",
40
- "@cumulus/message": "18.3.2",
41
- "@cumulus/types": "18.3.2",
35
+ "@aws-sdk/client-secrets-manager": "^3.621.0",
36
+ "@cumulus/aws-client": "18.4.0",
37
+ "@cumulus/common": "18.4.0",
38
+ "@cumulus/errors": "18.4.0",
39
+ "@cumulus/logger": "18.4.0",
40
+ "@cumulus/message": "18.4.0",
41
+ "@cumulus/types": "18.4.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": "8c143e0c25d02585653d50ccec150df2ec3b3160"
53
+ "gitHead": "05912dd9f996ec1149ecd11ed69ec42f86f0fc8a"
54
54
  }