
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@cooperco/contentful-cli-migrations
Advanced tools
Contentful CLI Migrations is a JavaScript open-source library for automating Contentful migrations. It provides a convenient way to manage and apply migrations to your Contentful space using the command line.
Note: This is NOT the official Contentful Migration tool, but it's based on it. That can be found on GitHub 🔗 or NpmJS 🔗
✨ Features · 💡 Installation · 📟 Example · 🎹 Usage · 🐦 Write Migrations · 📅 ToDo · 👾 Contributors · 🎩 Acknowledgments · 📚 Collection · 📄 License
To use this helper library, you must have Node.js 🔗 and npm 🔗 installed.
To install it, simply run:
npm install contentful-cli-migrations --save
Or, if using yarn 🔗:
yarn add contentful-cli-migrations
Similarly, if you are using Bun 🔗, just run:
bun add contentful-cli-release
node >= 18.0.0npm >= 9.5.0contentful-management >= 7.50.0contentful-migration ^4.9.4Create a migrations/scripts/ directory in your project. This directory will contain your migration scripts.
Define your migration scripts inside the migrations/scripts/ directory. Each migration script should be as follows:
0001-migration.cjs, 0002-migration.cjs, and so on.-). In this way the script can intercept
them.0001- and not 1-).0002 and 02 will be considered duplicated)..js or .cjs depending on the use of "type": "module" in your package.json.In Contentful, you will need what we call a 'Counter' entry. It means that you will need to create an entry and assign one of its field to register the latest migration that has run successfully.
en-US or en-GB.Note: the entry can stay in 'draft' status, since it doesn't need to be published to be used.
Set up your .env/.env.local configuration file to specify the required environment and migration settings. The
configuration options include:
CMS_MANAGEMENT_TOKEN: The Contentful CMA token for accessing your Contentful space.CMS_SPACE_ID: The ID of your Contentful space.CMS_MIGRATIONS_DIR: The path to the migrations directory in your project.CMS_MIGRATIONS_COUNTER_ID: The ID of the entry used to store the migration counter.CMS_MIGRATIONS_COUNTER_FIELD: The ID of the field in the counter entry that stores the actual migration counter.CMS_MIGRATIONS_COUNTER_LOCALE: The locale used to retrieve the migration counter from the field.You can define these options in a configuration file (e.g., .env) or pass them as command-line arguments when running the migrations.
When you start your project with contentful you usually start with an empty master environment. We have few advices
on how to keep the migrations as clean as possible for different environments:
en-US) and eventually additional locales.master environment as a new environment (ie: empty-DO-NOT-DELETE).
This will ensure a clean environment where you could run a Contentful import or the migrations.--initialise to
set up the counter content-type and entry for you.master environment, take note of the entry-id, field-id and locale. When
duplicating master for your dev or staging environments, these values will remain the same (so you won't have to
get confused with different values for different environments).Once everything is set up, running migrations is actually pretty simple
npx contentful-cli-migrations --to "<environment-id>"
The --to (or --environment-id) is the only mandatory command line option. And it tells the environment to apply the
migrations 'to'.
Since the management token would give you access to all environments, there is no default environment value in the
.env file, forcing you to specify the target environment for 'safety' reasons (surely you don't want to run them on
master accidentally).
This script can be used from the command line and accepts various arguments for customization:
--to or --environment-id [MANDATORY]: The environment id to which migrations will be executed.--space-id: The Contentful space id.--management-token or --mt: The Contentful Management Token.--migrations-dir: To specify a custom directory for the migrations (default is sub-directory CMS_MIGRATIONS_DIR
or migrations/scripts in your project root). The script will exit if this custom folder doesn't exist.--initialise: This might be needed the first time to 'override' trying to read a Content-type and an Entry that
don't exist yet. If you already have your environment set up, you can just create a counter entry of one of your
existing Content-types, and skip this option.--counter-id: The ID of the entry used to store the migration counter.--counter-field: The ID of the field in the counter entry that stores the actual migration counter. Example: title.--counter-locale: The locale used to retrieve the migration counter from the field. Default: en-US--force-yes: The script runs a migration at a time, asking you to confirm it manually (Y/N). In a CD/CI pipeline,
you will need to set up --force-yes so that all migrations will run without any request for interaction.There are some guidelines and some few tricks that can be implemented when writing a Contentful migration. For more info, look at the separate documentation on How to Write Migrations.
@fciacchi | @psyvic | @aalduz | @leslyto |
Feel free to open issues or pull requests in our GitHub Repository if you have suggestions or improvements to propose.
I would like to express my gratitude to the following parties:
Thank you to everyone involved!
We produce a bunch of interesting packages for Contentful. You might want to check them out:
This project is licensed under the MIT License
FAQs
Contentful CLI Migration Tool
We found that @cooperco/contentful-cli-migrations demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.