Skip to content

Commit

Permalink
add partition key to cosmosdb script and remove entity name from part…
Browse files Browse the repository at this point in the history
…ition key
  • Loading branch information
lenchvolodymyr committed Jan 19, 2021
1 parent c10452b commit 260cd69
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 6 additions & 0 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
try {
const _ = app.require('lodash');
const script = {
partitionKey: getPartitionKey(_)(data.containerData),
indexingPolicy: getIndexPolicyScript(_)(data.containerData),
sample: data.entities.map(entityId => updateSample(
JSON.parse(data.jsonData[entityId]),
Expand All @@ -25,6 +26,7 @@ module.exports = {
try {
const _ = app.require('lodash');
const script = {
partitionKey: getPartitionKey(_)(data.containerData),
indexingPolicy: getIndexPolicyScript(_)(data.containerData),
sample: updateSample(
JSON.parse(data.jsonData),
Expand Down Expand Up @@ -58,6 +60,10 @@ const updateSample = (sample, containerData, entityData) => {
};
};

const getPartitionKey = (_) => (containerData) => {
return _.get(containerData, '[0].partitionKey[0].name');
};

const add = (key, items, mapper) => (script) => {
if (!items.length) {
return script;
Expand Down
12 changes: 1 addition & 11 deletions forward_engineering/applyToInstance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ const updateIndexingPolicy = (indexes) => {
return result;
};

const getPartitionKey = (_) => (containerData) => {
const partitionKey = _.get(containerData, '[0].partitionKey[0].name');

if (!partitionKey) {
return;
}

return '/' + partitionKey.split('.').slice(1).join('/');
};

const getUniqueKeys = (uniqueKeys) => {
if (!uniqueKeys) {
return [];
Expand Down Expand Up @@ -116,7 +106,7 @@ module.exports = {

const { container, resource: containerDef } = await database.containers.createIfNotExists({
id: containerId,
partitionKey: getPartitionKey(_)(containerData),
partitionKey: script.partitionKey,
defaultTtl: helper.getTTL(containerData),
});

Expand Down
3 changes: 3 additions & 0 deletions properties_pane/container_level/containerLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ making sure that you maintain a proper JSON format.
"propertyType": "fieldList",
"template": "orderedList",
"templateOptions": {
"divider": "/",
"front": true,
"entityName": false,
"maxField": 1
}
},
Expand Down

0 comments on commit 260cd69

Please sign in to comment.