Skip to content

Reshard copy: skip catalogued NOT NULL constraints (PG 18 sources)#924

Merged
benben merged 1 commit into
mainfrom
ben/reshard-skip-notnull-constraints
Jul 9, 2026
Merged

Reshard copy: skip catalogued NOT NULL constraints (PG 18 sources)#924
benben merged 1 commit into
mainfrom
ben/reshard-skip-notnull-constraints

Conversation

@benben

@benben benben commented Jul 9, 2026

Copy link
Copy Markdown
Member

A real cnpg→external reshard on mw-dev failed at the constraint replay:

apply constraint ducklake_data_file_data_file_id_not_null on ducklake_data_file: ERROR: syntax error at or near "NOT" (SQLSTATE 42601)

(The rollback worked as designed — org back on the shard, unblocked.)

Cause: the cnpg shards run PG 18, which catalogues NOT NULL as pg_constraint rows (contype 'n', new in 18). pg_get_constraintdef renders them as NOT NULL <col>, and the ALTER TABLE … ADD CONSTRAINT … NOT NULL <col> form only parses on PG 18+ — the older external-RDS target rejects it. They're also fully redundant: the copier's CREATE TABLE already applies column-level NOT NULL from pg_attribute.attnotnull.

Fix: skip contype 'n' in the replay (shouldReplayConstraint), with a unit test pinning the replayed set (p/u/f/c/x yes, n no).

Why e2e missed it: the ext→cnpg positive path copies from an older-PG RDS (no 'n' rows exist there); the PG-18-source direction (cnpg→ext) is unit-only per the resharding contract — the harness has no RDS password, which the start API requires ephemerally.

🤖 Generated with Claude Code

A real cnpg->ext reshard failed at the constraint-replay step:

  apply constraint ducklake_data_file_data_file_id_not_null on
  ducklake_data_file: ERROR: syntax error at or near "NOT" (SQLSTATE 42601)

The cnpg shards run PG 18, which catalogues NOT NULL as pg_constraint
rows (contype 'n'); pg_get_constraintdef renders them as
"NOT NULL <col>", whose ALTER TABLE ... ADD CONSTRAINT form only
parses on PG 18+ — an older external-RDS target rejects it. They are
also fully redundant: the copier's CREATE TABLE already applies
column-level NOT NULL from pg_attribute.attnotnull.

Skip contype 'n' in the replay. Not caught by the ext->cnpg e2e because
that direction copies FROM an older-PG RDS, which has no 'n' rows; the
PG-18-source direction (cnpg->ext) is unit-only per the resharding
contract.
@benben benben enabled auto-merge (squash) July 9, 2026 15:01
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Test Impact Plan

Deterministic summary of how this PR changes tests, CI runners, and coverage-risk signals.

Summary

Area Added Changed Deleted
Test files 1 0 0
E2E/journey files 0 0 0
Workflow files 0 0 0

Signals

  • Test cases: +1 / -0
  • Assertions: +1 / -0
  • Skips or known failures added: 1
  • Workflow continue-on-error added: 0
  • Workflow path filters added: 0
  • Test commands removed from justfile: 0
  • E2E/journey retry lines added: 0

Coverage risk: likely reduced

Warnings

  • New skips or known failures (likely reduced)
    • 1 skip/allowlist line(s) added

@benben benben merged commit 36dfc3a into main Jul 9, 2026
22 checks passed
@benben benben deleted the ben/reshard-skip-notnull-constraints branch July 9, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant