@chkit/plugin-obsessiondb

中文文档
0.2.0-beta.16发布于 2026/11/09MITTypeScriptES Module构建来源已验证近 30 天下载 1.2万

ObsessionDB managed ClickHouse integration plugin for chkit

原始使用文档
文档目录9 节
  1. Features
  2. Why
  3. Install
  4. Usage
  5. How it works
  6. Examples
  7. What gets rewritten
  8. Documentation
  9. License

@chkit/plugin-obsessiondb

ObsessionDB companion plugin for chkit. This plugin is designed for ObsessionDB users who also need to target regular ClickHouse instances (e.g. local development, self-hosted staging).

Part of the chkit monorepo. This plugin extends the chkit CLI so one set of schema files works against both ObsessionDB and regular ClickHouse.

Features

  • storage_policy stripping -- Removes the storage_policy table setting, whose ObsessionDB policies (e.g. 's3') don't exist on a regular ClickHouse server, when targeting non-ObsessionDB instances
  • Host auto-detection -- Inspects clickhouse.url to determine whether the target is ObsessionDB or regular ClickHouse, no manual configuration needed
  • CLI flag overrides -- --force-shared-engines and --no-shared-engines flags to override auto-detection for a single generate or snapshot rebuild run
  • Applied by generate and snapshot rebuild -- migrate, status, drift, and check work from the migration files and snapshot those commands write
  • Views and materialized views are untouched -- Only table definitions are rewritten

Why

ObsessionDB uses Shared engine variants (e.g. SharedReplacingMergeTree, SharedMergeTree) to deliver managed replication without operator intervention. These engines don't exist in regular ClickHouse, so chkit always writes the standard engine name (SharedReplacingMergeTree(ts) becomes ENGINE = ReplacingMergeTree(ts)) and ObsessionDB substitutes the Shared variant on the server.

storage_policy is a standard ClickHouse table setting, but the storage policies ObsessionDB provides, such as 's3', are not defined on a regular ClickHouse server, so CREATE TABLE fails there with Unknown storage policy. This plugin intercepts schema definitions before the diff/planning pipeline and strips storage_policy, whatever its value, when the target is not ObsessionDB, so you can use a single set of schema files across both ObsessionDB and regular ClickHouse.

Install

bun add -d @chkit/plugin-obsessiondb

Usage

Register the plugin in your config:

// clickhouse.config.ts
import { defineConfig } from '@chkit/core'
import { obsessiondb } from '@chkit/plugin-obsessiondb'

export default defineConfig({
  schema: './src/db/schema/**/*.ts',
  outDir: './chkit',
  plugins: [
    obsessiondb(),
  ],
  clickhouse: {
    url: process.env.CLICKHOUSE_URL ?? 'http://localhost:8123',
  },
})

The rewrite runs automatically whenever generate or snapshot rebuild loads the schema.

How it works

  1. Auto-detection (default): The plugin inspects your clickhouse.url config value. If the host is an ObsessionDB instance (.obsessiondb.com or obsession.numia-dev.com), storage_policy is kept. Otherwise, it is stripped.

  2. Force flags: Override auto-detection for a single generate or snapshot rebuild run:

    • --force-shared-engines -- Keep storage_policy, even when the URL is not recognized as ObsessionDB (e.g. a service behind a custom domain)
    • --no-shared-engines -- Strip storage_policy, even on ObsessionDB

    If both are passed, --force-shared-engines wins. The migration files and snapshot.json keep what the flag decided, so pass the same flag on every generate and snapshot rebuild for that target. migrate, status, drift, and check accept both flags but ignore them.

Examples

# Auto-detect based on clickhouse.url (default behavior)
bunx chkit generate

# Strip storage_policy even when targeting ObsessionDB
bunx chkit generate --no-shared-engines

# Keep it for an ObsessionDB service behind a custom domain
bunx chkit generate --force-shared-engines
bunx chkit snapshot rebuild --force-shared-engines

What gets rewritten

SchemaGenerated DDL (every target)
engine: 'SharedMergeTree'ENGINE = MergeTree()
engine: 'SharedReplacingMergeTree(ts)'ENGINE = ReplacingMergeTree(ts)
engine: 'SharedAggregatingMergeTree'ENGINE = AggregatingMergeTree()
engine: 'MergeTree'ENGINE = MergeTree()
Table settingRegular ClickHouseObsessionDB
storage_policy (any value)strippedkept
Any other settingkeptkept

Only table definitions are affected. Views and materialized views are passed through unchanged.

Documentation

See the chkit documentation.

License

MIT

版本与发布记录

@chkit/plugin-obsessiondb 共发布 35 个版本,首次发布于 2026/02/24;过去 12 个月发布了 35 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0-beta.16latest2026/11/09今天
0.2.0-beta.142026/11/081 天前
0.2.0-beta.132026/11/081 天前
0.2.0-beta.122026/11/045 天前
0.2.0-beta.112026/10/1228 天前
0.2.0-beta.82026/09/291 个月前

关于 @chkit/plugin-obsessiondb 的常见问题

@chkit/plugin-obsessiondb 是什么?

ObsessionDB managed ClickHouse integration plugin for chkit

如何安装 @chkit/plugin-obsessiondb?

在项目目录运行 npm install @chkit/plugin-obsessiondb,或使用 pnpm add / yarn add / bun add。

@chkit/plugin-obsessiondb 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@chkit/plugin-obsessiondb 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@chkit/plugin-obsessiondb 可以商用吗?

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

@chkit/plugin-obsessiondb 的下载量有多少?

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

@chkit/plugin-obsessiondb 还在维护吗?

最新版本 0.2.0-beta.16 发布于 2026/11/09(今天);至今共发布 35 个版本,其中过去 12 个月发布了 35 个;首次发布于 2026/02/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。