DataProvider: AddColumn with inline checkConstraint duplicates check on subsequent migrate

未关闭
#69 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
csharp, postgres
领域
cli, databases

调研方向

Start with DataProviderMigrate and the AddColumnOperation path that handles column-level checkConstraint values; reproduce the schema from the issue against Postgres and inspect the generated DDL. Add or update coverage for the migration, then verify that one named check constraint is created and a subsequent migrate succeeds without a duplicate-constraint error.

由索引模型根据 Issue 内容生成。

描述

Tool: DataProviderMigrate (CLI)
Version: latest as of 2026-05-20 (installed via dotnet tool)
Provider: postgres (Supabase)

Symptom

A migrate --allow-destructive run fails with:

Error: migration apply failed: 42710: constraint "tenant_credit_event_kind_chk" for relation "tenant_credit_event" already exists

…even when starting from a state where the column and the constraint do not yet exist (verified via information_schema.columns + pg_constraint before the run).

Schema

- name: tenant_credit_event
  columns:
    - name: kind
      type: Text
      isNullable: false
      checkConstraint: "kind IN ('topup','spend','refund','adjustment')"

Hypothesis

AddColumnOperation with an inline checkConstraint appears to emit two
DDL statements in the same transaction:

  1. ALTER TABLE … ADD COLUMN kind text NOT NULL (which Postgres auto-names the
    inline constraint, e.g. tenant_credit_event_kind_check)
  2. ALTER TABLE … ADD CONSTRAINT tenant_credit_event_kind_chk CHECK (kind IN (…))

The second emit collides because the inline form was already applied — OR
DataProvider is emitting the named CONSTRAINT twice in a single batch.

Same shape visible on usage_events where prod has both
usage_events_kind_check AND usage_events_kind_chk (and equivalent
duplicates for charged_micro_usd, vendor_micro_usd, quantity). That's
the smoking gun — a previous successful run left one of each pair behind,
proving DataProvider is creating two constraints per column-level
checkConstraint.

Workaround used (prod hotfix)

Manually applied missing schema deltas via raw SQL (per user authorization
in the credit-billing rollout):

  • ALTER TABLE … ADD COLUMN kind text NOT NULL (no inline check)
  • ALTER TABLE … ADD CONSTRAINT tenant_credit_event_kind_chk CHECK … (named, once)
  • Renamed usage_events.ledger_id → credit_event_id
  • DROP TABLE wallet_ledger, DROP TABLE wallet
  • Replaced two combined RLS policies with the four single-op ones declared
    in migrations/schema.yaml.

Ask

Either:

  1. Emit only the named constraint from checkConstraint: and skip the
    inline form, OR
  2. Detect existing equivalent check constraints (same predicate / same
    relation) and treat as a no-op when re-applying.

Cross-refs

  • NAP incident: Nimblesite/NimblesiteAgenticPlatform#126
  • PR that triggered: Nimblesite/NimblesiteAgenticPlatform#125
主要语言
C#
星标
68
派生
4
平均合并
50 分钟
30 天内合并 PR
2

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Nimblesite/DataProvider 的其他 Issue

查看 Nimblesite/DataProvider 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。