跳转到内容
搜索文档

更新日志

Cloudflare 的最新更新与改进。

Back to all posts

新的 Durable Object 命名空间必须使用 SQLite 存储后端

如果您的账户中尚无基于键值 (KV) 后端的 Durable Object 命名空间,您将无法再创建新的此类命名空间。新的 Durable Object 命名空间必须使用 SQLite 存储后端。自 2024 年该后端正式商用 (GA) 以来,我们一直推荐所有新的 Durable Objects 使用该后端。

通过 new_sqlite_classes 迁移创建一个新类:

{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "migrations": [
    {
      "tag": "v1",
      "new_sqlite_classes": [
        "MyDurableObject"
      ]
    }
  ]
}
[[migrations]]
tag = "v1"
new_sqlite_classes = ["MyDurableObject"]

基于 SQLite 的 Durable Objects 与键值后端具有同等的功能特性——包括键值存储 API——并且还支持关系型 SQL 查询以及 时间点恢复 (PITR),可将对象存储恢复到过去 30 天内的任意时间点。

如果您尝试在受影响的账户上创建新的基于键值的命名空间(使用 new_classes 迁移),部署将失败并显示以下错误:

Creating new key-value backed Durable Object namespaces is no longer supported on this account. Please create a namespace using a `new_sqlite_classes` migration instead.

此更改仅影响尚未开始使用键值存储后端的账户。拥有至少一个现有基于键值命名空间的账户目前仍可创建新的命名空间,而 Workers 免费计划一直以来仅支持基于 SQLite 的 Durable Objects。这是向将 SQLite 作为 Durable Objects 单一存储后端迈出的更广泛一步,为未来现有基于键值对象的迁移路径做准备。

欲了解更多信息,请参阅 Durable Objects 迁移