Bug: CHECK constraint with a disjunction predicate ("x IS NULL OR x IN (...)") is dropped + re-added on every migrate (non-idempotent)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by tracing SchemaDiff's PostgreSQL CHECK-constraint comparison and reproduce the provided YAML case with migrate against PostgreSQL 16. Compare the YAML predicate with the pg_catalog form and verify that a second migrate produces zero operations for both the disjunction and existing simple checks.
由索引模型根据 Issue 内容生成。
描述
Summary
A converged database should produce zero operations on a re-run (per the migrations docs: "Re-running against a converged database → zero operations (idempotent)"). But a CHECK constraint whose YAML predicate contains a boolean disjunction (e.g. x IS NULL OR x IN (...)) is dropped and re-added on every migrate run. Plain IN (...) / single-comparison checks are correctly idempotent.
Environment
- DataProviderMigrate built from source at v0.9.12-beta (commit
8e3af36) --provider postgres, PostgreSQL 16
Repro
A table with two checked columns:
columns:
- { name: status, type: Text, isNullable: false, checkConstraint: "status IN ('active','done')" } # idempotent ✓
- { name: recurrence_kind, type: Text, checkConstraint: "recurrence_kind IS NULL OR recurrence_kind IN ('daily','weekly')" } # churns ✗
migrate once (converges), then migrate again against the unchanged DB:
Phase: all — applying 4 of 4 operation(s):
DropCheckConstraintOperation
AddCheckConstraintOperation # <- the recurrence_kind check, every single run
...
Run a third time → identical 4 ops. The churn is perpetual.
Root cause (hypothesis)
SchemaDiff compares the YAML predicate string against the pg_catalog-normalized form. Postgres stores:
CHECK (((recurrence_kind IS NULL) OR (recurrence_kind = ANY (ARRAY['daily'::text, 'weekly'::text]))))
The differ appears to normalize the simple IN (...) → = ANY (ARRAY[...]) case (those match → no churn), but does not canonicalize a disjunction (... IS NULL OR ...), so the comparison never matches and it drops + re-adds forever.
Impact
- Breaks the documented idempotency guarantee.
- Every CI/build
migrateperforms needless DDL — each drop+add takes anACCESS EXCLUSIVElock on the table. - Real drift on that constraint can be masked by the constant churn.
Suggested fix
Canonicalize CHECK expressions on both sides before diffing (parse to an AST, or compare the pg_get_constraintdef-normalized text rather than the raw YAML string). Failing that, document that check predicates must be authored in pg-normalized form.
Workaround
For Option-style nullable enums the IS NULL OR prefix is redundant anyway — a SQL CHECK passes when its predicate is TRUE or NULL, so CHECK (col IN (...)) already permits NULL. Dropping the prefix restored idempotency. But disjunctions are legitimate in general and should diff cleanly.
- 主要语言
- C#
- 星标
- 68
- 派生
- 4
- 平均合并
- 50 分钟
- 30 天内合并 PR
- 2
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Nimblesite/DataProvider 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 92/100
Nimblesite/DataProvider#137 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
Nimblesite/DataProvider#72 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
Nimblesite/DataProvider#121 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
Nimblesite/DataProvider#108 ·
维护者通常 1 天内回复
-
A check constraint the schema cannot name can never be retired, and keeps enforcing the old rule未关闭
难度 4/5 3-5 天 新手友好度 48/100
Nimblesite/DataProvider#107 ·
维护者通常 1 天内回复
查看 Nimblesite/DataProvider 的全部 Issue
相似的 Issue
-
bug priority:low severity:S3
难度 2/5 1-3 小时 新手友好度 68/100
squid-farm/talewright#909 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 82/100
-
kronos:develop:queued priority:P0
难度 2/5 1-3 小时 新手友好度 76/100
-
priority:P2
难度 1/5 1 小时以内 新手友好度 92/100