Contentstack CLI: Migrations, Seeding and Automation
Clicking through the UI to change 50 entries is slow and error-prone. The Contentstack CLI (csdx) lets you automate schema changes, content migrations, and environment setup.
Install and Log In
npm install -g @contentstack/cli
csdx config:set:region AWS-NA # or EU, Azure, GCP regions
csdx auth:login
You can also use management tokens with aliases for CI.
Export and Import Stacks
csdx cm:stacks:export --stack-api-key <key> --data-dir ./backup
csdx cm:stacks:import --stack-api-key <new-key> --data-dir ./backup
Use for backups, cloning stacks for testing, or seeding new environments.
Migration Scripts
Write migrations in JavaScript — like database migrations for your content:
module.exports = async ({ migration }) => {
const blog = migration.editContentType('blog_post');
blog.createField('reading_time')
.displayName('Reading time (min)')
.data_type('number');
};
csdx cm:migration --file-path ./migrations/001-add-reading-time.js --alias prod
Migrations can also transform existing entries — for example, splitting a "full name" field into first and last name.
Bulk Operations
csdx cm:entries:publish --content-types blog_post --environments production --locales en-us
Bulk publish, unpublish, and update operations are handy after migrations or for scheduled campaigns.
In CI/CD
- Run migrations on a branch, test, then merge
- Seed preview environments for pull requests
- Export nightly backups
Tips
- Keep migrations in version control alongside frontend code
- Run against a branch first, never directly on
main - Make migrations idempotent where possible
Treat content models like code: versioned, reviewed, and deployed by scripts.