GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing www.contentstack.com — Migrate your Content using the CLI Migration Command | V2.x.x | Contentstack Migrate your Content using the CLI Migration CommandupdateLast updated August 26, 2026 The migration command in Contentstack CLI allows developers to automate the content migration process using a custom migration script. This guide explains how to migrate your content using the CLI migration plugin. We have provided sample migration scripts that developers can use to get started, or you can write your custom scripts. Developers can validate the deployment before pushing it on production, using a test space to run the migration scripts. Additional ResourceFor more information, refer to the migration API documentation and advanced examples. Process OverviewThe first step is to write a migration script to perform content migration. We have provided sample migration scripts which you can refer here, or write custom scripts. Furthermore, you can use various methods and SDK instances to make your migration script easy to write and read. After writing the migration script, use the CLI migration command to migrate your content to the destination stack. Now let us understand how to migrate content from one stack to another using the CLI migration command. Prerequisites
Steps for Execution
Get Started with the Migration ScriptNow let’s understand how to create and execute migration scripts using Contentstack CLI. Furthermore, we will discuss various methods for making migration scripts easier to write and more readable. Create Migration FileFirst, determine the location where the migration script will be written. The migration script file will be exported when the migration command is run, accordingly, you can decide the location. Now, you must specify the file path of the migration script to run the migration process, as mentioned in the migration command. Developers can use JavaScript to create migration scripts that specify changes to a content model. Here’s a sample code snippet for you to get started. Copy the sample code and initiate with your migration script. 1234567 'use strict';
module.exports = async ({migration, stackSDKInstance}) => {
// write your scripts here
})The script file of the code should have a function exported as default, that's the method where the scripts reside. NoteDevelopers can modify the code to meet their specific requirements. Let's discuss the objects we used in the above example. 1 “migration” This refers to your migration object. The migration object has some predefined methods to perform various tasks like create, edit, and so on. Consider this example, where we have defined a method for creating the Blog content type. 1234567891011121314151617181920 module.exports = async ({ migration, stackSDKInstance }) => {
const blog = migration
.createContentType("blog")
.title("Blog")
.description('The is Blog content type')
.isPage(true)
.singleton(false);
blog
.createField("title")
.display_name("Title")
.data_type("text")
.mandatory(true);
blog
.createField("url")
.display_name("URL")
.data_type("text")
.mandatory(true);
migration.addTask(blog.getTaskDefinition());
};The last line of the code defines the migration task to execute the method. 1 “stackSDKInstance” This is an SDK instance initiated with an API key and the authentication method is chosen via the CLI. This is an optional object users can add to customize tasks that are not supported by the migration script. Currently, the migration script only supports content type-related methods. To extend your migration further, you can use this pre-initiated SDK instance to run the file via the CLI. Consider this example where we are creating an entry for the Blog content type. 123456789101112131415161718192021222324252627282930313233 module.exports = async ({ migration, stackSDKInstance }) => {
const createEntryTask = () => {
return {
title: "Create blog entries",
successMessage: "Entry created successfully",
failedMessage: "Failed to create entry",
task: async () => {
try {
let entry = {
title: `Awesome Blog`,
url: `/awesome-blog`,
};
await stackSDKInstance
.contentType("blog")
.entry()
.create({ entry });
} catch (error) {
throw error;
}
},
};
};
migration.addTask(createEntryTask());
};Carefully observe the SDK instance we have added to this example which extends our migration script and enables us to perform operations with entries in the content type. Similar to the previous example, the last line of the code defines the migration task and adds this method to the existing migration tasks list for execution. Additional ResourceFor more information, refer to the migration API documentation and advanced examples. Execute the Migration FileAfter configuring the migration script file, you can proceed to run the file via Contentstack CLI to complete the migration. If management token is not specified, by default migration plugin uses Auth token: 1 csdx cm:stacks:migration --file-path <file_path> -k <api_key> Migrate content using management token alias: 1 csdx cm:stacks:migration -a <alias> --file-path <file_path> -k <api_key> Additional ResourceCheck out our GitHub repository for detailed information on the migration script and various advanced options & examples. Warning CLI migration plugin is not ideal for branch merge. Points to Remember
| ||||||||||||||||||||||||
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |