The latest Gartner Peer Insights ‘Voice of the Customer’: WCM 2019 report is here! Get the report
blog Development

Automate Migrations with the Command Line Interface (CLI)

By Corey Hamilton Feb 18, 2020

Deploying changes to a new environment can be a nerve-wracking experience if there are questions about environmental differences or whether all related items have been accounted for. Fortunately, automating this process removes many of those questions early on, resulting in a more dependable environment and fewer headaches for developers.

To make this experience easier, the Kontent team has created a Command Line Interface (CLI) framework for migrating content updates to different environments. This framework can be combined with your favorite continuous integration tool to deploy changes as part of your automated deployment process. It leverages the latest improvements to our Management API, which added the ability to programmatically update content types and associated content items.

Execution of the Kontent CLI running a migration

One of the most common use cases we hear from developers has to do with changes to an existing content type. Not only does the content type need to be updated and deployed to a testing environment, but the content items associated with it often need to be updated to fit the new structure as well.

Recently, we ran into this challenge on our own kontent.ai website. When we first built the website, we created a content type to display information for each of our partners. After launching the new website, we began to get feedback that several partners wanted to have all of their regional offices listed on their profile page—but we had only built the content type to account for a single location. To handle this change, we took the following steps to update our content type and partner data, and then deploy those changes to our testing environment to ensure we weren’t going to break anything on the production website.

  1. We set up our testing environment to utilize the CLI, according to the CLI Documentation.
  2. We created a new Address content type so that each partner address was saved as its own content item.
  3. We updated our partner content type to support multiple linked items of the new Address content type.
  4. Next, we pulled the list of content items that used the Partner content type, and took the data from the original Address field to create new content items (using the new Address content type).
  5. Using that same list of Partner content, we updated each item to link to the appropriate Address content items for that partner.
  6. Then, we updated our application code to retrieve address information from the new linked address items.
  7. We ran the migration scripts to deploy the new content type, associated content items, and application code to the testing environment.
  8. Once everything had been thoroughly tested, we removed the old address fields from the partner content type.
Creating a new content type in JavaScript, via the Management API

Of course, we don’t expect you to jump right into a live project and try this out for the first time. That’s why we’ve also created a CLI Migrations Boilerplate to provide you with examples to get your feet wet before using it on a real project.

Once you’ve given this a try, keep an eye out for future improvements to the developer experience with Kontent. We’re working on several exciting new features to further advance the code-first approach to content management while also making it easier to deploy to multiple environments. Lastly, we want to make sure we’re meeting all your development needs, so please reach out if there are other use cases you need help addressing.

Written by
Corey Hamilton

I’m the Director of Product Marketing at Kentico. In this role, I’m responsible for aligning Kontent to the needs of digitally mature organizations through go-to-market strategy, product launches, and positioning & messaging.

More articles from Corey

Subscribe to Kentico Kontent Newsletter

Stay in the loop. Get the hottest updates while they’re fresh!