AddColumn emits an inline CHECK, then the planner adds it again — 42710 on every ALTER-path migration

Đang mở
#96 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp, postgresql
Lĩnh vực
database

Hướng nghiên cứu

Start at AddColumnOperation and the diff engine that schedules AddCheckConstraintOperation, then reproduce the ALTER-path migration against an existing PostgreSQL table using the schema fragment in the report. Done means a column with checkConstraint produces one constraint and the migration applies without error 42710.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version

DataProviderMigrate 0.9.12-beta (current latest release).

Summary

Adding a column that declares checkConstraint to an existing table plans two
operations that both create the same constraint. The second one fails and the whole
migration rolls back, so the change can never be applied.

Phase: all — applying 4 of 4 operation(s):
  AddColumnOperation
  AddCheckConstraintOperation
  CreateRlsPolicyOperation
  CreateRlsPolicyOperation
Error: migration apply failed: 42710: constraint "tool_calls_execution_target_chk"
for relation "tool_calls" already exists

AddColumnOperation already emits the CHECK inline as part of the ADD COLUMN, and
the diff engine independently notices the constraint is absent and schedules
AddCheckConstraintOperation for it too.

Proof that AddColumn is the one creating it

After the failed run, the database has neither the column nor the constraint —
the apply is transactional and rolled back cleanly:

execution_target column : None | nullable: None | default: None
constraints             : []

So the constraint did not pre-exist. It existed by the time operation 2 ran, and the
only thing between those points is operation 1.

Schema fragment

- name: execution_target
  type: Text
  isNullable: false
  defaultValue: "'client'::text"
  checkConstraint: "execution_target IN ('client', 'workspace')"

Why this is easy to miss

It only occurs on the ALTER path. On a fresh database the table is created with the
column inline, so AddColumnOperation never runs and no duplicate is planned. Our
test suite migrates a throwaway Postgres from scratch on every run and is completely
green; only the migration against the long-lived database fails. Any project whose
tests build the schema fresh will pass CI and then fail in production.

Expected

Adding a column with checkConstraint to an existing table applies once. Either
AddColumnOperation emits the bare column and leaves the CHECK to
AddCheckConstraintOperation, or the diff engine does not schedule a constraint that
the column operation already carries.

Impact

There is no way to express this without working around the bug — checkConstraint on
a column is the only form the schema language offers (we use it 19 times), and
--phase structural still contains both operations. The migration is simply
unappliable, which blocks the deploy that depends on it.

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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Nimblesite/DataProvider

Tất cả issue của Nimblesite/DataProvider

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.