Skip to content

Commit a4b64ac

Browse files
authored
Merge pull request #30 from dannleed/fix/HCK-4224-fix-FE-script-generation
HCK-4224: fix generation azure cli fe script params
2 parents 76b92fe + a81e441 commit a4b64ac

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

forward_engineering/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const applyToInstanceHelper = require('./applyToInstance/applyToInstanceHelper');
1+
const applyToInstanceHelper = require('./applyToInstance');
22
const getIndexPolicyScript = require('./helpers/getIndexPolicyScript');
33
const { getUniqueKeyPolicyScript } = require('./helpers/getUniqueKeyPolicyScript');
44
const { buildAzureCLIScript } = require('./helpers/azureCLIScriptHelpers/buildAzureCLIScript');

forward_engineering/applyToInstance/applyToInstanceHelper.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { StoredProcedure, UserDefinedFunction, Trigger } = require('../../reverse_engineering/node_modules/@azure/cosmos');
22
const setUpDocumentClient = require('../../reverse_engineering/helpers/setUpDocumentClient');
3+
const { TTL_ON_DEFAULT, TTL_ON, TTL_OFF } = require('../../shared/constants');
34

45
const applyToInstanceHelper = (_) => ({
56
setUpDocumentClient(connectionInfo) {
@@ -59,12 +60,13 @@ const applyToInstanceHelper = (_) => ({
5960

6061
getTTL(containerData) {
6162
switch (containerData.TTL) {
62-
case 'On (no default)':
63+
case TTL_ON_DEFAULT:
6364
return -1;
64-
case 'On':
65-
return _.parseInt(TTLseconds) || 0;
65+
case TTL_ON:
66+
return _.parseInt(containerData.TTLseconds) || -1;
67+
case TTL_OFF:
6668
default:
67-
return -1;
69+
return 0;
6870
}
6971
},
7072

forward_engineering/applyToInstance/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const reApi = require('../../reverse_engineering/api');
22
const executeWithTimeout = require('../../reverse_engineering/helpers/executeWithTimeout');
3+
const { TTL_ON, TTL_ON_DEFAULT } = require('../../shared/constants');
34
const applyToInstanceHelper = require('./applyToInstanceHelper');
45

56
const createOrUpdate = async (sample, container) => {
@@ -93,10 +94,11 @@ module.exports = {
9394

9495
progress('Create container if not exists ...');
9596

97+
const shouldIncludeTtl = [TTL_ON, TTL_ON_DEFAULT].includes(containerData.TTL);
9698
const { container, resource: containerDef } = await database.containers.createIfNotExists({
9799
id: containerId,
98100
partitionKey: script.partitionKey,
99-
defaultTtl: helper.getTTL(containerData),
101+
...(shouldIncludeTtl && { defaultTtl: helper.getTTL(containerData) }),
100102
...(script.uniqueKeyPolicy && { uniqueKeyPolicy: script.uniqueKeyPolicy }),
101103
...helper.getContainerThroughputProps(containerData),
102104
});

forward_engineering/helpers/azureCLIScriptHelpers/buildAzureCLIScript.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ const getAzureCliContainerCreateStatement =
5959
const helper = applyToInstanceHelper(_);
6060

6161
const partitionKeyParams = getPartitionKeyParams(_)(containerData);
62-
const throughputParam = getThroughputParam(helper.getContainerThroughputProps(containerData));
62+
const throughputParam = getThroughputParam(helper.getContainerThroughputProps(containerData[0]));
6363
const indexingPolicyParam = `--idx ${escapeAndWrapInQuotes(
6464
JSON.stringify(getIndexPolicyScript(_)(containerData)),
6565
)}`;
6666
const uniqueKeysPolicyParam = getUniqueKeysPolicyParam(containerData[0], escapeAndWrapInQuotes);
67-
const ttlParam = `--ttl ${helper.getTTL(containerData[0])}`;
67+
const ttl = helper.getTTL(containerData[0]);
68+
const ttlParam = ttl !== 0 ? `--ttl ${helper.getTTL(containerData[0])}` : '';
6869

6970
const cliStatement = `${CLI} ${CONTAINER} ${CREATE}`;
7071
const requiredParams = [

reverse_engineering/api.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const _ = require('lodash');
55
const axios = require('axios');
66
const qs = require('qs');
77
const executeWithTimeout = require('./helpers/executeWithTimeout');
8+
const { TTL_ON_DEFAULT, TTL_ON, TTL_OFF } = require('../shared/constants');
89
let client;
910

1011
module.exports = {
@@ -142,9 +143,11 @@ module.exports = {
142143
accountID: data.accountKey,
143144
defaultConsistency: accountInfo.consistencyPolicy,
144145
preferredLocation: accountInfo.writableLocations[0] ? accountInfo.writableLocations[0].name : '',
145-
tenant: data.tenantId,
146-
resGrp: data.resourceGroupName,
147-
subscription: data.subscriptionId,
146+
...(includeAccountInformation && {
147+
resGrp: data.resourceGroupName,
148+
tenant: data.tenantId,
149+
subscription: data.subscriptionId,
150+
}),
148151
},
149152
additionalAccountInfo,
150153
);
@@ -657,9 +660,9 @@ async function getUdfs(containerInstance) {
657660

658661
function getTTL(defaultTTL) {
659662
if (!defaultTTL) {
660-
return 'Off';
663+
return TTL_OFF;
661664
}
662-
return defaultTTL === -1 ? 'On (no default)' : 'On';
665+
return defaultTTL === -1 ? TTL_ON_DEFAULT : TTL_ON;
663666
}
664667

665668
function getSamplingInfo(recordSamplingSettings, fieldInference) {
@@ -773,7 +776,7 @@ function createSchemaByPartitionKeyPath(path, documents = []) {
773776
};
774777
};
775778

776-
const getProperties = (paths) => {
779+
const getProperties = paths => {
777780
return paths.reduce((result, path) => {
778781
if (!path || !_.isString(path)) {
779782
return result;
@@ -790,9 +793,9 @@ function createSchemaByPartitionKeyPath(path, documents = []) {
790793

791794
return {
792795
...result,
793-
...getNestedObject(namePath)
794-
}
795-
}, {})
796+
...getNestedObject(namePath),
797+
};
798+
}, {});
796799
};
797800

798801
if (!Array.isArray(path)) {

shared/constants.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ const PARTITION_KEY_KIND = {
66
MultiHash: 'MultiHash',
77
};
88

9+
const TTL_ON = 'On';
10+
const TTL_OFF = 'Off';
11+
const TTL_ON_DEFAULT = 'On (no default)';
12+
913
module.exports = {
1014
PARTITION_KEY_DEFINITION_VERSION,
1115
PARTITION_KEY_KIND,
16+
TTL_ON,
17+
TTL_OFF,
18+
TTL_ON_DEFAULT,
1219
};

0 commit comments

Comments
 (0)