Skip to content

Standalone CAMO project using Javascript migration files

Sam Bauers edited this page May 25, 2022 · 2 revisions

Create a new project

Using your favourite package manager:

# Create a new project directory
$ mkdir my-camo-js
$ cd my-camo-js

# npm
$ npm init

# or yarn
$ yarn init

# or ppm
$ pnpm init

Then answer all the package manager setup questions.

Install CAMO package

# npm
$ npm install --save-dev @sambauers/camo

# or yarn
$ yarn add --dev @sambauers/camo

# or pnpm
$ pnpm add --save-dev @sambauers/camo

Add a migrate script to your package.json

In your projects package.json add a migrate script in the scripts definitions:

{
  "scripts": {
    "migrate": "camo"
  }
}

Create a migrations directory

$ mkdir migrations

Setup the required environment variables

Create a .env file in the project root containing (at least):

# Contentful Active Migration Organiser (CAMO)
# The space ID to connect to
CONTENTFUL_MIGRATION_SPACE_ID='<your-contentful-space-id>'

# The access token to connect with
CONTENTFUL_MIGRATION_ACCESS_TOKEN='<your-contentful-access-token>'

Create the Contentful migrations content type

Run the migrate --list command:

# npm
$ npm run migrate --list

# or yarn
$ yarn migrate --list

# or pnpm
$ pnpm migrate --list

You will be asked if you want CAMO create the content type in Contentful.

Create a local migration file

Create a migration file in the migrations folder with your desired schema.

List the local migration file

The file you created above should now be visible with the --list option

# npm
$ npm run migrate --list

# or yarn
$ yarn migrate --list

# or pnpm
$ pnpm migrate --list

Apply the local migration file

The file you created above should now be applied when running CAMO

# npm
$ npm run migrate

# or yarn
$ yarn migrate

# or pnpm
$ pnpm migrate