0

We are trying to setup a workflow for delivering content model changes to our other environments (stage & prod).

Right now, our approach is this:

  1. Create a new contentful field as a migration script using Contentful CLI.
  2. Run script in local dev to make sure the result is as desired using contentful space migration migrations/2023-01-12-add-field.ts
  3. Add script to GIT in folder migrations/[date]-[description].js
  4. When release to prod, run all scripts in the migrations folder, in order, as part of the build process.
  5. When folder contains "too many" scripts, and we are certain all changes are applied to all envs, manually remove the scripts from GIT and start over in an empty folder.

Where it fails

But, between point 4 & 5 there will be cases where a script has already been run in an earlier release, and that throws an error:

enter image description here

I would like the scripts to continue more gracefully without throwing an error, but I cant find support for it in the space migration docs. I have tried wrapping the code in try/catch without any luck.

Contentful recommends using the Content Migration API in favour for Content Management API since it is faster. I guess we could use the Content Management API, but at the same time we want to use "best practise".

Are we missing something here?

I would like to do something like:

module.exports = function (migration) {
  // Create a new category field in the blog post content type.
  const blogPost = migration.editContentType('blogPost')

  if (blogPost.fieldExists('testField')) {
    console.log('Field already exists')
  } else {
    blogPost.createField('testField').name('Test field').type('Symbol')
  }
}
chilly
  • 193
  • 2
  • 13

0 Answers0