Sign inSign up

marcomontalbano/contentful-migration

By marcomontalbano

•Updated over 2 years ago

Run Contentful migrations more easily with just one command.

Image
Content management system
0

653

marcomontalbano/contentful-migration repository overview

⁠Contentful Migration

Test Npm Docker

Run Contentful migrations more easily with just one command.

⁠Usage

With this Docker image you don't even need Node.js

docker run --rm --tty --name contentful-migration-runner -e CONTENT_MANAGEMENT_TOKEN=$CONTENT_MANAGEMENT_TOKEN -e SPACE_ID=$SPACE_ID -e ENVIRONMENT_ID=$ENVIRONMENT_ID -v $(pwd)/migrations:/app/migrations marcomontalbano/contentful-migration
⁠Options
⁠Environment Variables
  • CONTENT_MANAGEMENT_TOKEN - required - Contentful Content Management Token. You can create one from the section API keys under your space settings.

  • SPACE_ID - required - Contentful Space ID. You can get the Space ID from the section General settings under your space settings. The Space ID is also visibile in the url.

  • ENVIRONMENT_ID - required - Contentful Environment ID.

⁠Volumes
  • /app/migrations - required - Migrations folder.
⁠Arguments
  • --cfmversion 4.0.0 - optional - Use this argument if you want to change the contentful-migration version. (default to latest)

⁠Migrations folder

Either you use Docker or CLI, you should create a /migrations (or whatever name) folder. This folder will contain all your migration description files.

A migration description file is a .js or .ts file that contains a migration script. This scripts are written using Contentful Migration⁠ syntax which you are already familiar with.

The filename must follow this naming convention:

<version> - <description> .ts

version starts from 1 and must be incremental.

description is used to easily recognize the purpose of the migration.

A real example can be: 1-create-author.ts


e.g. javascript

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

e.g. typescript

import { MigrationFunction } from 'contentful-migration'

const migrate: MigrationFunction = (migration) => {
  const author = migration.createContentType('author');
  const name = author.createField('name');
  name.type('Symbol').required(true);
}

export = migrate

Read more⁠

Tag summary

Content type

Image

Digest

sha256:03915e819…

Size

72.9 MB

Last updated

over 2 years ago

docker pull marcomontalbano/contentful-migration