Skip to content

Commit

Permalink
Merge pull request #15 from lenchvolodymyr/fix/partition-key
Browse files Browse the repository at this point in the history
Fix/partition key
  • Loading branch information
lenchvolodymyr authored Jan 19, 2021
2 parents 8fd3b09 + 260cd69 commit 8723d2a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "CosmosDB-with-SQL-API",
"version": "0.1.21",
"versionDate": "2021-01-08",
"version": "0.1.22",
"versionDate": "2021-01-15",
"author": "hackolade",
"engines": {
"hackolade": "4.3.1",
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 8723d2a

Please sign in to comment.