@devaltitude/contentful-migrate

中文文档
1.0.0发布于 2025/08/29MIT近 30 天下载 2927

[AS] 具有国家管理能力的移徙工具

中文使用文档
文档目录9 节
  1. 安装
  2. 使用量
  3. 输入
  4. 拖带
  5. 创建
  6. 列表
  7. 上来
  8. 下来
  9. 写入迁移

内容迁移工具

npm contentful-migration version Build Status Downloads

这是来自原始内容模版软件包的叉子

我们的目标是根据我们的需要更新一揽子计划

通过创建增量脚本修改来管理您的内容性计划 。 这个项目是基于所暴露的想法 内 内容的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

写入迁移

有关如何写作迁移的更多信息,请参见: 有意义的移徙文件

此工具基于 节点移动为更多 关于如何管理迁移的信息,见 正在迁移

版本与发布记录

@devaltitude/contentful-migrate 共发布 1 个版本,首次发布于 2025/08/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2025/08/291.2 年前

关于 @devaltitude/contentful-migrate 的常见问题

@devaltitude/contentful-migrate 是什么?

[AS] 具有国家管理能力的移徙工具

如何安装 @devaltitude/contentful-migrate?

在项目目录运行 npm install @devaltitude/contentful-migrate,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ctf-migrate,可以用 npx ctf-migrate 直接运行。

@devaltitude/contentful-migrate 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/devaltitude__contentful-migrate 是否存在。

@devaltitude/contentful-migrate 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@devaltitude/contentful-migrate 可以商用吗?

@devaltitude/contentful-migrate 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@devaltitude/contentful-migrate 的下载量有多少?

根据 npm 官方下载统计,@devaltitude/contentful-migrate 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,927 次,日均约 98 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devaltitude/contentful-migrate 还在维护吗?

最新版本 1.0.0 发布于 2025/08/29(1.2 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。