@defrex/autobuild-postgres-store

中文文档
1.6.0发布于 2026/11/12Apache-2.0TypeScriptES Module近 30 天下载 3298
原始使用文档
文档目录3 节
  1. Setup
  2. Public entry points
  3. Concurrency

@defrex/autobuild-postgres-store

Serverless-safe Autobuild persistence using PostgreSQL and either an S3-compatible object store or Vercel Blob. This is a separate package: installing the @defrex/autobuild CLI does not install its database/blob provider dependencies. A project that embeds the adapter adds it directly:

bun add @defrex/autobuild-postgres-store

Only this package's src/ tree and this README publish to npm: every consumer of the published package imports through the manifest's exports and bin, all of which live under src/. The manifest's files allowlist pins the tarball to exactly that, and bun tools/publish-contents-check.ts in the repository check gate fails when anything else would ship. The deny-by-default allowlist is deliberate: a future top-level file in this package (a scratch script, a live-test fixture, a dotenv file, an editor artifact) stays out of the tarball unless the allowlist and the check are updated together. The src/testing/ helpers are test-only surface — their sole consumer is the live test suite — and are excluded from the tarball by the !src/testing/** negation (AUT-500), so a surface pass does not re-flag them.

Setup

To run the migration from the hosted deployment's own checkout, choose the adapter-compatible tag shown in GitHub Releases, then obtain and install that exact repository revision in a dedicated checkout:

git clone --depth 1 --branch v0.6.0 --single-branch https://github.com/defrex/autobuild.git autobuild-v0.6.0
cd autobuild-v0.6.0
bun install --frozen-lockfile
DATABASE_URL=postgres://… bun run postgres:migrate

Replace v0.6.0 with the selected release tag. The migration is idempotent. The adapter reads the conventional DATABASE_URL, which Vercel's Neon and Postgres storage integrations inject; set AB_POSTGRES_URL to override it explicitly. Schema diagnostics refer to the root postgres:migrate script in this pinned release checkout. The database identity needs permission to create tables, constraints, and migration markers during migration and to select, insert, update, and delete the resulting tables at runtime. The ticket schema has its own version/checksum marker, so migrating an existing BuildStore v1 database adds project-scoped tickets, comments, and blockers without replacing the established BuildStore marker. Opening against a missing, older/newer, or checksum-mismatched schema fails; schema creation is never implicit.

Populated legacy ticket-v1 upgrades also require the running service's blob backend, credentials, access mode and prefix. The environment-aware migration CLI opens blobs lazily to read each registered project's selected effective configuration when ownership must be inferred. Registered projects without a run/config reference make no claim. Unreadable selected configs stop unchanged; restoring their bytes or assigning every remaining legacy team unblocks migration. Complete registered owner assignments avoid unrelated configuration reads. Fresh installs, empty-v1 upgrades and v2 reruns remain SQL-only. Released main-v9 upgrades import AB_WEB_REPOSITORIES once inside that same transaction. On failure, main promotion and registry import roll back with tickets. Owner projects add and tickets assign-team independently bootstrap their registry/recovery journals on v9, so they remain usable after rollback. Ambiguous teams stop unchanged; the owner resolves them with ab-hosted-store tickets assign-team TEAM REPOSITORY --user IDENTITY before rerunning migration. See the hosted-service migration procedure.

The current DDL of every marker — build store, ticket, and auth — is immutable once a database has deployed it: deployed databases carry that exact DDL's checksum, and editing the DDL in place leaves them all incompatible. Every schema change is therefore a new version — the four-step rule: freeze the previous DDL verbatim with its checksum, add an upgrade branch for it in migratePostgres, bump the schema version, and update the committed pin in schema-guard.test.ts. An edit to any current DDL or version without the matching pin update fails the integration suite with a message that names those four steps.

The pin is a tripwire, not an enforced coupling, and it cannot mechanically force the version bump: the pin is the only committed record of the released checksum, and an author who edits the current DDL and re-pins only the pin's checksum — leaving the pinned version and the exported version constants unchanged — passes the integration suite. Deployed databases then still carry the pre-edit checksum of a version whose DDL has changed, and the next openPostgresBuildStore or migratePostgres fails with a diagnostic naming that cause. Follow all four steps on every schema change; the migration diagnostic exists to catch the shortcut after the fact.

Public entry points

The package exposes four subpaths, each named after the source module it publishes:

  • @defrex/autobuild-postgres-store — the full adapter surface: openPostgresBuildStore, openPostgresBuildStoreFromEnv, migratePostgres, ticket and blob stores.
  • @defrex/autobuild-postgres-store/env — URL resolution helpers (resolvePostgresUrl, describePostgresTarget).
  • @defrex/autobuild-postgres-store/schema — schema DDL, version and checksum constants, schema assertions, and migratePostgres.
  • @defrex/autobuild-postgres-store/store — openPostgresBuildStore, the PostgresBuildStore class, PostgresBuildStoreOptions, and EVENT_WAIT_POLL_MS.

Concurrency

Identity rows are created conflict-safely before being locked for subsequent work. Concurrent repository ensures are idempotent and all return the single stored record. Concurrent attempts to create the same build slug produce one winner; every other caller receives build "<slug>" already exists rather than a raw PostgreSQL uniqueness error.

import { openPostgresBuildStoreFromEnv } from '@defrex/autobuild-postgres-store'

const store = await openPostgresBuildStoreFromEnv(process.env)

S3 credentials need GetObject and PutObject on the configured bucket/prefix. Only an object-store 404 is treated as absent; authorization and service errors are propagated. Vercel supports either a Blob read-write token or a Vercel OIDC token paired with its Blob store ID.

PostgresTicketDatabase.source({ repo, teamKey, lifecycle, claimedState?, createState? }) creates a request-bound TicketSource view. The deployment supplies the project identity, readable-id prefix, and lifecycle names. Ticket bodies are stored as PostgreSQL text and returned unchanged.

For an authenticated HTTP deployment of this adapter, see the @defrex/autobuild-hosted-store-service guide.

版本与发布记录

@defrex/autobuild-postgres-store 共发布 23 个版本,首次发布于 2026/09/17;过去 12 个月发布了 23 个版本。

版本发布日期距今
1.6.0latest2026/11/12今天
1.5.02026/11/092 天前
1.4.22026/11/048 天前
1.4.12026/11/038 天前
1.4.02026/11/039 天前
1.3.02026/10/2913 天前

其他发布通道:beta → 1.0.0-beta.4。

关于 @defrex/autobuild-postgres-store 的常见问题

如何安装 @defrex/autobuild-postgres-store?

在项目目录运行 npm install @defrex/autobuild-postgres-store,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ab-postgres-store,可以用 npx ab-postgres-store 直接运行。

@defrex/autobuild-postgres-store 支持 TypeScript 吗?

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

@defrex/autobuild-postgres-store 支持 ESM 还是 CommonJS?

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

@defrex/autobuild-postgres-store 可以商用吗?

@defrex/autobuild-postgres-store 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@defrex/autobuild-postgres-store 的下载量有多少?

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

@defrex/autobuild-postgres-store 还在维护吗?

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