{"id":15101396,"url":"https://github.com/ehsanmajd/contentful-migrate","last_synced_at":"2025-10-08T08:32:22.393Z","repository":{"id":57206460,"uuid":"344478835","full_name":"ehsanmajd/contentful-migrate","owner":"ehsanmajd","description":"🐎 Schema migration tooling for Contentful, with state management","archived":false,"fork":true,"pushed_at":"2021-03-11T18:21:22.000Z","size":610,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-08T15:27:39.811Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.contentful.com/blog/2018/09/13/content-model-changes-scale-telus-cms-as-code/","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"deluan/contentful-migrate","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ehsanmajd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-04T13:11:13.000Z","updated_at":"2021-03-04T13:40:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ehsanmajd/contentful-migrate","commit_stats":null,"previous_names":["bemaxima/contentful-migrate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmajd%2Fcontentful-migrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmajd%2Fcontentful-migrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmajd%2Fcontentful-migrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmajd%2Fcontentful-migrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ehsanmajd","download_url":"https://codeload.github.com/ehsanmajd/contentful-migrate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235700110,"owners_count":19031668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T18:22:14.046Z","updated_at":"2025-10-08T08:32:22.067Z","avatar_url":"https://github.com/ehsanmajd.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Contentful Migrate Tool\n\n[![npm](https://img.shields.io/npm/v/contentful-migrate.svg)](https://www.npmjs.com/package/contentful-migrate)\n[![contentful-migration version](https://img.shields.io/npm/dependency-version/contentful-migrate/contentful-migration)](https://www.npmjs.com/package/contentful-migration)\n[![Build Status](https://github.com/deluan/contentful-migrate/workflows/CI/badge.svg)](https://github.com/deluan/contentful-migrate/actions)\n[![Downloads](https://img.shields.io/npm/dm/contentful-migrate)](https://www.npmjs.com/package/contentful-migrate)\n\nManage your Contentful schema by creating incremental scripted changes. This project is based on the ideas exposed\nin [Contentful's CMS as Code article](https://www.contentful.com/r/knowledgebase/cms-as-code/)\n\nScripts are written using [Contentful's migration tool](https://github.com/contentful/contentful-migration) syntax. Ex:\n\n```javascript\nmodule.exports.description = \"Create Post model\";\n\nmodule.exports.up = migration =\u003e {\n  const post = migration\n    .createContentType(\"post\")\n    .name(\"Post\")\n    .displayField(\"title\")\n    .description(\"Post model\");\n\n  post\n    .createField(\"title\")\n    .name(\"Title\")\n    .type(\"Symbol\")\n    .required(true)\n    .localized(false);\n};\n\nmodule.exports.down = migration =\u003e {\n  migration.deleteContentType(\"post\");\n};\n```\n\nThis command line tool is designed to keep track of changes of content types individually. It keeps the\nscripts in a `migrations` folder in your project. This folder must contain one subfolder for each\ncontent type. Ex:\n\n```\nyour-project\n├── README.md\n├── migrations\n│   ├── banner\n│   │   └── 1513743198536-create-banner.js\n│   └── post\n│       ├── 1513695986378-create-post.js\n│       └── 1513716408272-add-date-field.js\n├── package.json\n.\n.\n.\n\n```\n\nFor more information on schema migrations technique and practice, see:\n\n- [Evolutionary Database Design](https://martinfowler.com/articles/evodb.html)\n- [Schema migration](https://en.wikipedia.org/wiki/Schema_migration)\n\n## Installation\n\n```sh\nnpm install -g contentful-migrate\n```\n\n## Usage\n\nMost of the available commands need a\n[personal access token](https://www.contentful.com/developers/docs/references/authentication/)\nfor accessing the CMA (Contentful Management API). You can pass the token using the `--access-token`\noption or setting an environment variable called `CONTENTFUL_MANAGEMENT_ACCESS_TOKEN`\n\nSimilarly, a default contentful space and environment id can be specified by setting the `CONTENTFUL_SPACE_ID`\nand `CONTENTFUL_ENV_ID` environment variables, which will be used as defaults for any command that accepts\nthe `--space-id` and `--environment-id` options.\n\n### init\n\nCreates the content type 'Migration' into the designated contentful space. This will be\nused to keep track of the current state of each managed content type.\n\n```\n  Usage: ctf-migrate init [options]\n\n  Options:\n\n    -t, --access-token [access-token]  CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty\n    -s, --space-id [space-id]          space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)\n    -e, --environment-id [env-id]      id of the environment within the space (defaults to environment variable CONTENTFUL_ENV_ID if set, otherwise defaults to 'master')\n```\n\nIf the target space already has been init'd before, it will throw an error:\n\n`Content type with id \"migration\" already exists.`\n\n### bootstrap\n\nCreate your migration files for content models already in your space. It gives you the option to squash any previous migration state.\nNote: It will delete any existing migration scripts and create a consolidated one for each specified content type.\n\n```\n  Usage: ctf-migrate bootstrap [options]\n\n  Options:\n\n    -t, --access-token [access-token]  CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty\n    -s, --space-id [space-id]          space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)\n    -e, --environment-id [env-id]      id of the environment within the space (defaults to environment variable CONTENTFUL_ENV_ID if set, otherwise defaults to 'master')\n    -c, --content-type [content-type]  one or more content type to bootstrap with choice to overwrite migration state\n    -a, --all                          apply bootstrap to all with choice to overwrite migration state\n```\n\nExample: executing the command `ctf-migrate bootstrap -c post -s \u003cspace-id\u003e` will create a file where the `up` command will generate the exact snapshot of the `Post` content model\n\n### create\n\nCreates an empty time stamped file in the content-type's migrations folder.\n\n```\n  Usage: ctf-migrate create \u003cname\u003e [options]\n\n  Options:\n\n    -c, --content-type \u003ccontent-type\u003e  content type name\n```\n\nExample: executing the command `ctf-migrate create create-post-model -c post` will create\na file named `./migrations/post/1513695986378-create-post.js` (the timestamp will vary)\n\n### list\n\nLists all migrations for the given content-types, also indicating whether they were already\napplied and when.\n\n```\n  Usage: ctf-migrate list [options]\n\n  Options:\n\n    -t, --access-token [access-token]  CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty\n    -s, --space-id [space-id]          space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)\n    -e, --environment-id [env-id]      id of the environment within the space (defaults to environment variable CONTENTFUL_ENV_ID if set, otherwise defaults to 'master')\n    -c, --content-type [content-type]  one or more content type names to list\n    -a, --all                          lists migrations for all content types\n```\n\nExample:\n\n```bash\n$ ctf-migrate list -s i2ztmmsocxul -c post banner\nListing post\n  [2017-12-19 22:12:58] 1513695986378-create-post.js : Create Post model\n  [pending] 1513716408272-add-title-field.js : Adds title field\nListing banner\n  [2018-01-08 15:01:45] 20180103165614-create-banner.js : Create Banner model\n  [2018-01-22 11:01:33] 20180111172942-add-subtitle-field.js: Add Subtitle field\n```\n\nFor the `post` model in this example, the first script (`create-post.js`) has already been applied but the\nsecond one (`add-title-field.js`) has not. For the `banner` model, all scripts have been applied.\n\n### up\n\nMigrates up to a specific version or all pending scripts if a filename is not informed. This will apply pending scripts for\nthe specified content-type into the specified space.\n\n```\n  Usage: ctf-migrate up [filename] [options]\n\n  Options:\n\n    -t, --access-token [access-token]  CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty\n    -s, --space-id [space-id]          space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)\n    -e, --environment-id [env-id]      id of the environment within the space (defaults to environment variable CONTENTFUL_ENV_ID if set, otherwise defaults to 'master')\n    -c, --content-type [content-type]  one or more content type names to process\n    -a, --all                          processes migrations for all content types\n    -d, --dry-run                      only shows the plan, don't write anything to contentful. defaults to false\n```\n\n### down\n\n\u003e **ATTENTION**: As noted in the [CMS as Code article](https://www.contentful.com/r/knowledgebase/cms-as-code/#how-to-get-started),\n\"in real-world situations there is often no real way to down migrate content without resorting to backups\". Even though\nwe agree with that assertion, we still think there is value in having a `down` function to make it easier to develop\nand debug the `up` migration scripts (when you're working on a dev/test space), as it makes it easy to revert your\nchanges and try again, without resorting to any manual intervention.\\*\n\nMigrates down to a specific version or just the last one if filename is not informed. This will roll back applied scripts\nfor the specified content-type from the specified space.\n\n```\n  Usage: ctf-migrate down [filename] [options]\n\n  Options:\n\n    -t, --access-token [access-token]  CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty\n    -s, --space-id [space-id]          space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)\n    -e, --environment-id [env-id]      id of the environment within the space (defaults to environment variable CONTENTFUL_ENV_ID if set, otherwise defaults to 'master')\n    -c, --content-type [content-type]  content type name\n    -d, --dry-run                      only shows the plan, don't write anything to contentful. defaults to false\n```\n\n## Writing Migrations\n\nFor more information on how to write migrations, see\n[Contentful migrations documentation](https://github.com/contentful/contentful-migration#documentation--references)\n\nThis tool is based on [node-migrate](https://github.com/tj/node-migrate). For more\ninformation on how to run migrations, see [Running migrations](https://github.com/tj/node-migrate#running-migrations)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsanmajd%2Fcontentful-migrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fehsanmajd%2Fcontentful-migrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsanmajd%2Fcontentful-migrate/lists"}