{"id":15101367,"url":"https://github.com/deluan/contentful-migrate","last_synced_at":"2025-10-08T08:32:18.047Z","repository":{"id":29415349,"uuid":"121620086","full_name":"deluan/contentful-migrate","owner":"deluan","description":"🐎 Schema migration tooling for Contentful, with state management","archived":true,"fork":false,"pushed_at":"2023-06-16T20:06:59.000Z","size":450,"stargazers_count":60,"open_issues_count":34,"forks_count":37,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-07T14:54:44.152Z","etag":null,"topics":["cms-as-code","contentful"],"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":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deluan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-15T11:08:15.000Z","updated_at":"2024-02-18T21:18:07.000Z","dependencies_parsed_at":"2024-06-18T20:11:17.123Z","dependency_job_id":"01bd75e0-3018-477a-86be-88314b731ee7","html_url":"https://github.com/deluan/contentful-migrate","commit_stats":{"total_commits":212,"total_committers":14,"mean_commits":"15.142857142857142","dds":0.4056603773584906,"last_synced_commit":"4231ccf14a49e35cdb8d58d5c925473532f1dd83"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deluan%2Fcontentful-migrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deluan%2Fcontentful-migrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deluan%2Fcontentful-migrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deluan%2Fcontentful-migrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deluan","download_url":"https://codeload.github.com/deluan/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":["cms-as-code","contentful"],"created_at":"2024-09-25T18:21:24.094Z","updated_at":"2025-10-08T08:32:17.718Z","avatar_url":"https://github.com/deluan.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\n# NOTICE: As I haven't worked with Contentful for a few years now, I'm not able to keep maintaning this tool. \n# For this reason, I decided to archive this repository. \n# If you want to evolve and maintain it, please let me know and I can un-archive it and add you as a maintainer.\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\nIf you don't wish to have your migrations directory in the root of your project, you can configure the name and location by setting the CONTENTFUL_MIGRATIONS_DIR environment variable, e.g. `/path/to/project/foo/contentful-migrations`\n\n\u003e **ATTENTION**: The migrations directory should always be a folder under the project's root (or under some subdir inside the root). Placing the directory outside of the project's version control could lead to the migration code and Contentful schema becoming out-of-sync.\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%2Fdeluan%2Fcontentful-migrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeluan%2Fcontentful-migrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeluan%2Fcontentful-migrate/lists"}