

The migration script // This is how to start building a migration script. If successful, it'll show you your space name alongside your space-id. And -default-locale if you want to set a default locale that isn't us-En. You might need -management-token and pass in your content management key.

When you run the script, you will first get an overview of the changes that will happen, and then you need to confirm that you actually want to apply these changes. Create a space contentful space create -name 'Your Space Name'. Then run the migration script: > contentful space migration -environment-id 'feature-1' my-migration.js We can do that with the methodīefore you run your script, remember to log in to Contentful and to select the correct space (see above for how). To be able to copy information from one entry to another, we also need to use the Contentful API directly. Now you can generate the Contentful export: contentful space export. You can find more examples in Contentful's documentation: Finally, copy the token and paste it into the contentful login prompt in your console. The migration script is in javascript, and the Contentful CLI has several useful functions built in to create migrations. > contentful space environment create -name "feature-1" -environment-id "feature-1" Log in to Contentful and select which space to use: > contenful loginĪdd a new environment called "feature-1".
Contentful copy space install#
Install the Contentful CLI, if you don't have it already: > npm install -g contentful-cli To summarize what we are going to changeīefore we begin, create a new environmentīy working with a new Contentful environment, you don't risk anything happening to your existing data. The 'mainImage' field is a link to an asset (an actual image file), the same asset linked from the child 'image' entry in the original content model. I want to add a new field 'mainImage', replacing 'image': This content model with references two levels deep just to display an image, feels too complex.
Contentful copy space code#
The 'image' field above is a reference to another content type 'image', which looks like this: Open the amerx file In the Code tab, click the access.ts file From the Contentful website, copy your spaces Space ID to the variable SPACEID. I have the following content model 'blogpost': The task: Transform the 'blogpost' content type by moving the image asset from one entry to another In this blogpost, I will show you how you can use the Contentful CLI in a migration script to copy content from one entry to another. Practically speaking, however, it is more useful to think of a space as serving a particular purpose.

From a simple perspective, spaces house content types, entries, and assets. By using migration scripts, you can add and delete fields like you can in the web app, and you can also create and insert content into existing entries. A space is a workspace that contains all content and media for a project. However, if you are planning more complex changes, migration scripts are probably the best way forward. This is pretty straightforward if you are doing basic changes like adding a new text field. In Contentful, the easiest way to change your content model is through the web app on.
