Skip to Content
Features履歴管理

履歴管理

履歴管理機能を使用すると、コンテンツの編集履歴を保存できます。誰が、いつ、どのような変更を行ったかを記録し、過去の状態に復元できます。

ユースケース例

CMSにコンテンツの履歴管理機能を実装することで、以下のように活用できます。

  • 誤って編集したデータを編集前の状態に復元する
  • 複数の編集者で作業する際に、誰がいつどのような変更を行ったか記録する

機能の有効化

スキーマで テーブル ごとに有効化できます。enableHistory プロパティを true に設定します。

orizm.config.ts
import { defineConfig } from "@orizm/cli/config"; export default defineConfig({ tables: { blog: { columns: {}, enableHistory: true, }, }, });

記録される情報

コンテンツに対する操作

コンテンツに対する以下の操作を記録します。

操作概要
createコンテンツの作成
updateコンテンツの更新
publishコンテンツの公開
unpublishコンテンツの非公開

編集したユーザー

操作を行ったCMSユーザーの情報を記録します。APIキーによる操作の場合は、APIキーの情報を記録します。

使用されたAPIの種類

以下のAPIの種類を記録します。

API概要
Developer API開発者コンソールからの操作
Management APICMSアプリケーションからの操作
Consumer APIConsumerアプリケーションからの操作

コンテンツの内容

コンテンツの内容を記録します。変更前後の比較や、以前の状態を復元する際に利用できます。

使い方

SDKを使った履歴管理機能の使い方を説明します。

履歴の取得

履歴を取得するには、CMS SDKの listHistory() メソッドを使用します。

await cmsClient.tables.blog.listHistory(id);

以下のように履歴情報が取得できます。

{ "contents": [ { "id": 2, "createdAt": "2025-01-02T00:00:00Z", "action": "publish", "developerAPI": false, "managementAPI": true, "consumerAPI": false, "projectUserId": "M3h4U0OZkiCBiaI8", "apiKey": null, "content": { "id": "GtWHkA8K90hBTXSk", "title": "記事タイトル", "body": "記事本文", "group": null, "scheduledPublishAt": null, "scheduledUnpublishAt": null, "_draft": false, "_published": true, "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-01-02T00:00:00Z", "publishedAt": "2025-01-02T00:00:00Z" } }, { "id": 1, "createdAt": "2025-01-01T00:00:00Z", "action": "create", "developerAPI": false, "managementAPI": true, "consumerAPI": false, "projectUserId": "M3h4U0OZkiCBiaI8", "apiKey": null, "content": { "id": "GtWHkA8K90hBTXSk", "title": "記事タイトル(下書き)", "body": "記事本文の下書き中です。", "group": null, "scheduledPublishAt": null, "scheduledUnpublishAt": null, "_draft": true, "_published": false, "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-01-01T00:00:00Z", "publishedAt": null } } ], "totalCount": 2 }

デフォルトでは最新の10バージョンが取得できます。第二引数にオプションを指定することで、取得件数やページングの設定ができます。

await cmsClient.tables.blog.listHistory(id, { limit: 10, offset: 0 });

コンテンツの復元

コンテンツを復元するには、復元したいバージョンの content プロパティのデータでコンテンツを更新してください。

// 履歴を取得 const { contents } = await cmsClient.tables.blog.listHistory(id); // 履歴から復元したいバージョンのデータを取得 const { title, body } = contents[0].content; // コンテンツを更新 await cmsClient.tables.blog.update(id, { title, body });

履歴では、記録時点のコンテンツをそのまま保持しています。そのためテーブルのカラム構成を変更している場合、過去と現在のデータ構造に互換性がない可能性があります。

Last updated on