Synchronize contentful environments via Contentful CLI

Labs & Tutorials

Wed, 05 Aug 2020

unsplash.com

  1. Export master and feature environment content model:
contentful space export --environment-id <branch> --space-id ndwvgngbqj68
  1. Compare them and find differences:

unsplash.com

  1. Create folder .src/migrations in your project:
  2. Add Contentful Migration DSL script for each change, a couple of examples:

4.1. Rename field:

    module.exports = function (migration) {
        const service = migration.editContentType('services');
        service.editField('serviceDescriptionRichText')
        .name('serviceDescriptionRichText');
    }

4.2. Create new field in content type (object approach):

module.exports = function (migration) {
    const policy = migration.editContentType('policies')
    policy.createField('richTextPolicyDescription',
        {
            "name": "richTextPolicyDescription",
            "type": "RichText",
            "localized": false,
            "required": false,
            "validations": [
            ],
            "disabled": false,
            "omitted": false
        })
}

5- Execute script:

contentful space migration --environment-id 'master' .\03-add-policy-richtext-field.js --space-id ndvgngbqj68
  1. Validate migration: unsplash.com

  2. New changes from contentful feature environment applied in master:

unsplash.com

Loading...

written by Senior Orc Developer