Skip to content

Commit

Permalink
Merge pull request #1231 from contentstack/fix/CS-43247
Browse files Browse the repository at this point in the history
fix: create, update , create-update entry migration script
  • Loading branch information
aman19K authored Jan 9, 2024
2 parents c227748 + 7afd151 commit f29b61f
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 206 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.19 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-branches/1.0.20 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.19",
"version": "1.0.20",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
15 changes: 11 additions & 4 deletions packages/contentstack-branches/src/branch/merge-handler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from 'os';
import path from 'path';
import forEach from 'lodash/forEach';
import { cliux } from '@contentstack/cli-utilities';
Expand Down Expand Up @@ -275,7 +276,7 @@ export default class MergeHandler {
deleted: [],
};

selectedMergeItems.forEach((item) => {
selectedMergeItems?.forEach((item) => {
mergeContent.content_types[item.status].push(item.value);
});
break;
Expand All @@ -290,10 +291,16 @@ export default class MergeHandler {
if (scriptFolderPath !== undefined) {
cliux.success(`\nSuccess! We have generated entry migration files in the folder ${scriptFolderPath}`);
cliux.print('\nWARNING!!! Migration is not intended to be run more than once. Migrated(entries/assets) will be duplicated if run more than once', {color: 'yellow'});

const migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config {compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath}} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`;

let migrationCommand: string;
if(os.platform() === 'win32'){
migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`;
}else{
migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config {compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath}} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`;
}

cliux.print(
`\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/migrate-branch-entries" to update the migration scripts, and then run the command:\n\n${migrationCommand}`,
`\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/entry-migration" to update the migration scripts, and then run the command:\n\n${migrationCommand}`,
{ color: 'blue' },
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function generateMergeScripts(mergeSummary, mergeJobUID) {
merge_existing_new: entryCreateUpdateScript,
merge_existing: entryUpdateScript,
merge_new: entryCreateScript,
ignore: entryCreateUpdateScript,
};

const processContentTypes = (contentTypes, messageType) => {
Expand Down Expand Up @@ -66,6 +65,8 @@ export function getContentTypeMergeStatus(status) {
return 'created';
} else if (status === 'merge_existing_new') {
return 'created_updated';
} else if (status === 'ignore') {
return;
} else {
return '';
}
Expand Down
Loading

0 comments on commit f29b61f

Please sign in to comment.