Bug: CHECK constraint with a disjunction predicate ("x IS NULL OR x IN (...)") is dropped + re-added on every migrate (non-idempotent)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C#
- Star
- 68
- Fork
- 4
- Merge trung bình
- 50 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Nimblesite/DataProvider
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 92/100
Nimblesite/DataProvider#137 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Nimblesite/DataProvider#72 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Nimblesite/DataProvider#121 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Nimblesite/DataProvider#108 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A check constraint the schema cannot name can never be retired, and keeps enforcing the old ruleĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Nimblesite/DataProvider#107 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Nimblesite/DataProvider
Issue tương tự
-
kronos:develop:queued priority:P0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
nopSolutions/nopCommerce#8512 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
modelcontextprotocol/csharp-sdk#2061 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày