内容迁移工具
这是来自原始内容模版软件包的叉子
我们的目标是根据我们的需要更新一揽子计划
通过创建增量脚本修改来管理您的内容性计划 。 这个项目是基于所暴露的想法 内 内容的CMS作为代码条款
脚本使用 内容的迁移工具 语法. 实例:
module.exports.description = "Create Post model";
module.exports.up = migration => {
const post = migration
.createContentType("post")
.name("Post")
.displayField("title")
.description("Post model");
post
.createField("title")
.name("Title")
.type("Symbol")
.required(true)
.localized(false);
};
module.exports.down = migration => {
migration.deleteContentType("post");
};
此命令行工具旨在单独跟踪内容类型的变化. 它会保持
脚本在一个 migrations 文件夹。 此文件夹必须包含每个子文件夹
内容类型。 实例:
your-project
├── README.md
├── migrations
│ ├── banner
│ │ └── 1513743198536-create-banner.js
│ └── post
│ ├── 1513695986378-create-post.js
│ └── 1513716408272-add-date-field.js
├── package.json
.
.
.
如果您不希望您的迁移目录位于您的工程的根中, 您可以设置 CANSTUL MIGRATIONS DIR 环境变量, 例如 . /path/to/project/foo/contentful-migrations
注意事项: 迁移目录应该始终是项目根下的一个文件夹(或者根内的某些子目录下). 将目录置于项目版本控制之外,可能导致迁移代码和Contentful schema 变得不同步.
关于计划迁移技术和实践的更多信息,见:
安装
npm install -g contentful-migrate
使用量
大多数可用的命令需要
个人访问令牌
用于访问CMA(Content Management API). 您可以使用 --access-token
选项或设置环境变量 CONTENTFUL_MANAGEMENT_ACCESS_TOKEN
同样,可以通过设置 CONTENTFUL_SPACE_ID
财务报告和审定财务报表 CONTENTFUL_ENV_ID 环境变量,将用作接受任何命令的默认值
页:1 --space-id 财务报告和审定财务报表 --environment-id 选项.
输入
创建内容类型“迁移”到指定内容空间。 这将是 用于跟踪每个管理内容类型的现状.
Usage: ctf-migrate init [options]
Options:
-t, --access-token [access-token] CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty
-s, --space-id [space-id] space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)
-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')
如果目标空间已经进入它之前,它会抛出一个错误:
Content type with id "migration" already exists.
拖带
为您空间中已经存在的内容模型创建您的迁移文件 。 它给了你一个选择 摧毁任何之前的迁移状态. 说明: 它将删除任何已存在的迁移脚本,并为每个指定的内容类型创建一个合并的脚本.
Usage: ctf-migrate bootstrap [options]
Options:
-t, --access-token [access-token] CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty
-s, --space-id [space-id] space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)
-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')
-c, --content-type [content-type] one or more content type to bootstrap with choice to overwrite migration state
-a, --all apply bootstrap to all with choice to overwrite migration state
示例: 执行命令 ctf-migrate bootstrap -c post -s <space-id> 将创建文件,其中 up 命令将生成精确的快照 Post 内容模式
创建
在内容类型的迁移文件夹中创建空时间戳文件 .
Usage: ctf-migrate create <name> [options]
Options:
-c, --content-type <content-type> content type name
示例: 执行命令 ctf-migrate create create-post-model -c post 将创建
文件名称 ./migrations/post/1513695986378-create-post.js (时间戳会不同)
列表
列出给定内容类型的所有迁移,同时注明是否已经 应用和时间.
Usage: ctf-migrate list [options]
Options:
-t, --access-token [access-token] CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty
-s, --space-id [space-id] space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)
-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')
-c, --content-type [content-type] one or more content type names to list
-a, --all lists migrations for all content types
示例
$ ctf-migrate list -s i2ztmmsocxul -c post banner
Listing post
[2017-12-19 22:12:58] 1513695986378-create-post.js : Create Post model
[pending] 1513716408272-add-title-field.js : Adds title field
Listing banner
[2018-01-08 15:01:45] 20180103165614-create-banner.js : Create Banner model
[2018-01-22 11:01:33] 20180111172942-add-subtitle-field.js: Add Subtitle field
给 post 本示例中的模型,第一个脚本(create-post.js)已经应用,但
第二组add-title-field.js没有。 给 banner 模式,所有脚本都已应用.
上来
如果一个文件名没有被通知, 则会忽略一个特定的版本或所有待决脚本 。 这将适用于待定的脚本 指定内容类型进入指定空间.
Usage: ctf-migrate up [filename] [options]
Options:
-t, --access-token [access-token] CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty
-s, --space-id [space-id] space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)
-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')
-c, --content-type [content-type] one or more content type names to process
-a, --all processes migrations for all content types
-d, --dry-run only shows the plan, don't write anything to contentful. defaults to false
下来
注意事项: 如报告所示 CMS 作为代码条款, (中文(简体) ), “在现实世界中, 通常没有真正的办法, 虽然 我们同意这一说法,我们仍然认为,有必要有一个
down功能,以方便开发 调试up迁移脚本(当您正在工作 dev/ test 空间时),因为它使得您很容易返回 改变并再次尝试,不诉诸任何人工干预
Migrates 下到一个特定的版本, 或者只是最后一个如果文件名没有被通知的话 。 这将滚回应用脚本 用于指定空间的指定内容类型.
Usage: ctf-migrate down [filename] [options]
Options:
-t, --access-token [access-token] CMA token, defaults to your environment variable CONTENTFUL_MANAGEMENT_ACCESS_TOKEN if empty
-s, --space-id [space-id] space id to use (defaults to environment variable CONTENTFUL_SPACE_ID)
-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')
-c, --content-type [content-type] content type name
-d, --dry-run only shows the plan, don't write anything to contentful. defaults to false
写入迁移
有关如何写作迁移的更多信息,请参见: 有意义的移徙文件