MCPcopy Index your code
hub / github.com/contentful/contentful-migration

github.com/contentful/contentful-migration @v5.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.0.0 ↗ · + Follow
1,609 symbols 3,981 edges 340 files 58 documented · 4% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

header

CI semantic-release npm downloads npm discord

contentful-migration - content model migration tool

Describe and execute changes to your content model and transform entry content.

What is Contentful?

Contentful provides content infrastructure for digital teams to power websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship their products faster.

Table of contents

Core Features

  • Content type
  • Edit Content type
  • Create a Content type
  • Entries
  • Transform Entries for a Given Content type
  • Derives a new entry and sets up a reference to it on the source entry
  • Updates tags on entries for a given Content Type
  • Fields
  • Create a field
  • Edit a field
  • Delete a field
  • Rename a field
  • Change a field's control
  • Reset a field's control
  • Copy a field's control
  • Move field
  • Tags
  • Create a Tag
  • Rename a Tag
  • Delete a Tag

Pre-requisites && Installation

Pre-requisites

  • Node LTS

Installation

npm install contentful-migration

Usage

:exclamation: Usage as CLI

We moved the CLI version of this tool into our Contentful CLI. This allows our users to use and install only one single CLI tool to get the full Contentful experience.

Please have a look at the Contentful CLI migration command documentation to learn more about how to use this as command line tool.

Usage as a library

const { runMigration } = require('contentful-migration')
const options = {
  filePath: '<migration-file-path>',
  spaceId: '<space-id>',
  accessToken: '<access-token>'
}
runMigration(options)
  .then(() => console.log('Migration Done!'))
  .catch((e) => console.error(e))

In your migration description file, export a function that accepts the migration object as its argument. For example:

module.exports = function (migration, context) {
  const dog = migration.createContentType('dog')
  const name = dog.createField('name')
  name.type('Symbol').required(true)
}

You can also pass the function directly. For example:

const { runMigration } = require('contentful-migration')

function migrationFunction(migration, context) {
  const dog = migration.createContentType('dog')
  const name = dog.createField('name')
  name.type('Symbol').required(true)
}

const options = {
  migrationFunction,
  spaceId: '<space-id>',
  accessToken: '<access-token>'
}

runMigration(options)
  .then(() => console.log('Migration Done!'))
  .catch((e) => console.error(e))

Documentation & References

Configuration

Name Default Type Description Required
filePath string The path to the migration file if migrationFunction is not supplied
migrationFunction function Specify the migration function directly. See the expected signature. if filePath is not supplied
spaceId string ID of the space to run the migration script on true
environmentId 'master' string ID of the environment within the space to run the false
accessToken string The access token to use true
yes false boolean Skips any confirmation before applying the migration,script false
retryLimit 5 number Number of retries before failure (every subsequent retry will increase the timeout to the previous retry by about 1.5 seconds) false
requestBatchSize 100 number Limit for every single request false
headers object Additional headers to attach to the requests false

Chaining vs Object notation

All methods described below can be used in two flavors:

  1. The chained approach:

    javascript const author = migration .createContentType('author') .name('Author') .description('Author of blog posts or pages')

  2. The object approach:

    javascript const author = migration.createContentType('author', { name: 'Author', description: 'Author of blog posts or pages' })

    While both approaches work, it is recommended to use the chained approach since validation errors will display context information whenever an error is detected, along with a line number. The object notation will lead the validation error to only show the line where the object is described, whereas the chained notation will show precisely where the error is located.

migration

The main interface for creating and editing content types and tags.

createContentType(id[, opts]) : ContentType

Creates a content type with provided id and returns a reference to the newly created content type.

id : string – The ID of the content type.

opts : Object – Content type definition, with the following options:

  • name : string – Name of the content type.
  • description : string – Description of the content type.
  • displayField : string – ID of the field to use as the display field for the content type. This is referred to as the "Entry title" in

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 930
Class 322
Function 252
Interface 102
Enum 3

Languages

TypeScript100%

Modules by API surface

index.d.ts91 symbols
src/lib/entities/content-type.ts72 symbols
src/lib/migration-steps/index.ts57 symbols
src/lib/intent/composed-intent.ts57 symbols
src/lib/intent/base-intent.ts54 symbols
src/lib/interfaces/intent.ts53 symbols
src/lib/offline-api/index.ts48 symbols
src/lib/migration-chunks/validation/editor-layout.ts41 symbols
src/lib/migration-chunks/validation/content-type.ts30 symbols
src/lib/migration-chunks/validation/tag.ts28 symbols
src/lib/intent/content-type-taxonomy-validation.ts24 symbols
src/lib/action/content-type-taxonomy-validation.ts18 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add contentful-migration \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page