/
🦒

Contentful migrations

javascript
On this page
  • Content & schema migrations

Content & schema migrations

For migrations you will need Contentful's command line interface tool.

Pre-requisites

  • Node LTS

Installation

Using homebrew:

sh
brew install contentful-cli

Using npm:

sh
npm install -g contentful-cli

Using yarn:

sh
yarn global add contentful-cli

Login

You will need to login to contentful on your computer. Run contentful login and follow the prompts, see below for an example:

sh
❯ contentful login
A browser window will open where you will log in (or sign up if you don’t have an account), authorize this CLI tool and paste your CMA token here:
? Open a browser window now? Yes
? Paste your token here: [hidden]
Great! Your CMA token is now stored on your system. (Located at /Users/zander/.contentfulrc.json)
You can always run contentful logout to remove it.

Create a new CMA token (personal access token) from this page.

Content modeling

Every time you need to modify a content model, a new migration script should be created. It needs to be carefully modeled so that you don't overwrite existing types and content.

For more information on how to model your content programmatically, see these docs

When editing existing fields, it can be useful to view the JSON representation of the content model to see what is there. e.g. app.contentful.com/spac...view

Useful links:

Running the migration

It is a good idea to create a test environment that is a clone of master so that everything can be checked before running the migration script "for real".

sh
contentful space migration --space-id a65gr7u3g09k --environment-id 'test' 01-add-article-cta-type.js
Edit this page
Want to make your own site like this?
Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My second brain, by Zander Martineau.