@gate-forge/pack-alembic

中文文档
0.19.2发布于 2026/11/10Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2445

Alembic migration obligations pack: static lineage verification, engine-run roundtrip on disposable database, data-preservation checks, and multi-developer merge safety.

原始使用文档

@gate-forge/pack-alembic

Opt-in Alembic migration obligations. A repository without an alembic key in .gateforge.yml behaves exactly as before; no migration obligations are added.

When enabled, Gateforge parses migration scripts with Python AST only, then runs upgrade → downgrade base → upgrade against an engine-created gf_tmp_<id> database and drops it. The trusted admin URL comes only from this configuration, never from the test environment. Suite claims cannot satisfy these obligations.

alembic:
  chains:
    - name: invoices
      migrations: migrations/versions
      models:
        - models.py
      # Optional; defaults shown:
      alembicIni: alembic.ini
      modelsModule: models
      metadata: Base.metadata
  scratch:
    adminUrl: postgresql://gateforge:[email protected]:5432/postgres
  # Optional: seed existing rows, verify counts/fingerprints, and declare renames.
  seed:
    path: tests/seed.sql
    tables:
      - name: invoices
        columns: [id, number]
        copies:
          - from: legacy_number
            to: number
  # Optional owner-approved irreversible revisions.
  irreversible: []
  # Optional; validates against target branch merge result.
  merge:
    targetRef: origin/main

gateforge init prints an opt-in template when alembic.ini exists; it does not enable the pack. Add the block to .gateforge.yml, provide a disposable Postgres service and a trusted admin URL, then run gateforge check.

The migration runner requires Alembic, SQLAlchemy, and a PostgreSQL driver (psycopg or psycopg2) in its Python environment. It does not import the project's env.py. The runner snapshots tables, columns, constraints, indexes, enums, and sequences, excluding alembic_version. With seed, it compares row counts and declared column fingerprints across the migration. A configured merge target is tested in a temporary Git worktree.

Cause codes (all additive): MIGRATION_MISSING, MIGRATION_LINEAGE_BROKEN, MIGRATION_DOWNGRADE_NOOP, MIGRATION_DRIFT, MIGRATION_ROUNDTRIP_FAILED, MIGRATION_DATA_LOST, MIGRATION_CONFLICT, MIGRATION_SCRATCH_UNSAFE.

Failure matrix

test/scanner.test.ts covers the static cases without a database: duplicate revision ids, dangling parents, and multiple heads, all read with Python AST only.

test/postgres.e2e.test.ts covers the engine-run cases on a disposable PostgreSQL instance. It is skipped, with a printed reason, unless GATEFORGE_ALEMBIC_TEST_ADMIN_URL is set to an admin URL of a throwaway instance (for example a CI postgres service container). GATEFORGE_ALEMBIC_TEST_PYTHON optionally selects an interpreter that already has Alembic, SQLAlchemy, and a PostgreSQL driver; it defaults to python3.

CaseCause code
model changed with no migration in the same changeMIGRATION_MISSING
downgrade() is empty or incompleteMIGRATION_DOWNGRADE_NOOP
migration chain does not match the modelsMIGRATION_DRIFT
destructive rename after the seed is loadedMIGRATION_DATA_LOST
two branches alter the same table, merge result keeps two headsMIGRATION_CONFLICT
merge revision breaks a seeded row on the merge resultMIGRATION_DATA_LOST
failure injected right after the scratch database is createdMIGRATION_ROUNDTRIP_FAILED, database dropped

The suite also asserts that only the gf_tmp_<id> name recorded during the run is dropped: a similarly named existing database and the configured application database both survive with their data.

packages/cli/test/alembic-first-run.test.ts proves the setup flow end to end: it copies examples/alembic into a fresh repository, runs gateforge init, writes the printed opt-in block verbatim (with the trusted admin URL filled in), and runs check and next. Without the block the run compiles no obligation at all; with it the engine witnesses the chain on a disposable database and the honest example produces no migration finding. Editing the model afterwards makes check and next report MIGRATION_DRIFT. It is skipped, with a printed reason, unless GATEFORGE_ALEMBIC_TEST_ADMIN_URL is set, and it needs python3 to carry Alembic, SQLAlchemy, and a PostgreSQL driver because the engine runs python3 exactly as production does.

版本与发布记录

@gate-forge/pack-alembic 共发布 34 个版本,首次发布于 2026/10/03;过去 12 个月发布了 34 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.19.2latest2026/11/105 天前
0.19.12026/11/106 天前
0.19.02026/10/2917 天前
0.18.32026/10/2522 天前
0.18.22026/10/2125 天前
0.18.12026/10/2125 天前

关于 @gate-forge/pack-alembic 的常见问题

@gate-forge/pack-alembic 是什么?

Alembic migration obligations pack: static lineage verification, engine-run roundtrip on disposable database, data-preservation checks, and multi-developer merge safety.

如何安装 @gate-forge/pack-alembic?

在项目目录运行 npm install @gate-forge/pack-alembic,或使用 pnpm add / yarn add / bun add。

@gate-forge/pack-alembic 支持 TypeScript 吗?

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

@gate-forge/pack-alembic 支持 ESM 还是 CommonJS?

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

@gate-forge/pack-alembic 需要什么版本的 Node.js?

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

@gate-forge/pack-alembic 可以商用吗?

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

@gate-forge/pack-alembic 的下载量有多少?

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

@gate-forge/pack-alembic 还在维护吗?

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