Skip to content

[PXT-477] Migration for existing PK tables (Agent Team approach) - #6

Open
Chrisclone wants to merge 2 commits into
christopherpestano:b-treefrom
Chrisclone:fix/pr1203-migration-team
Open

[PXT-477] Migration for existing PK tables (Agent Team approach)#6
Chrisclone wants to merge 2 commits into
christopherpestano:b-treefrom
Chrisclone:fix/pr1203-migration-team

Conversation

@Chrisclone

Copy link
Copy Markdown

PK Migration — Agent Team Approach

Apples-to-apples comparison with PR #5 (solo agent). Same task, same starting point, built by a 3-agent team (Coder → Tester → Red Team) using Claude Code Agent Teams.

Converter Design

  • Uses only table_modifier — no table_md_updater (avoids the metadata persistence bug that broke the solo v1)
  • copy.deepcopy + explicit conn.execute(sql.update) for both success and failure paths
  • pg_tables guard: skips if store table doesn't exist
  • pg_indexes idempotency: if index already exists, just syncs metadata
  • Savepoint isolation for index creation

Tests (362 lines)

  • Clean helper functions: _simulate_pre_migration(), _get_table_md(), _index_exists()
  • Happy path: index created, pg_indexes verified, PK enforcement works
  • Failure path: raw SQL duplicate insert, PK stripped, no index, rows preserved
  • Composite PK with string: left(col, 256) truncation verified
  • Composite PK with duplicates
  • Idempotency

Comparison with PR #5 (solo agent v2)

Solo v2 (PR #5) Team (this PR)
Converter lines 119 119
Test lines ~130 362
Rounds needed 2 (v1 buggy → v2 fixed) 1
pg_tables guard No Yes
Index exists guard No Yes
table_md_updater Used (caused v1 bug) Avoided entirely

Generated by OpenClaw Agent Team (Coder + Tester + Red Team)

christopherpestano and others added 2 commits March 27, 2026 04:24
…bles

Tables created with primary_key columns before PrimaryIndexMd was added
have is_pk flags on columns but no PrimaryIndexMd and no physical unique
index. This converter:

- For tables with is_pk columns but no primary_index_md: attempts to
  CREATE UNIQUE INDEX with SAVEPOINT isolation
- If succeeds: persists PrimaryIndexMd, logs success
- If fails (duplicate rows): strips is_pk from all columns, sets
  primary_index_md=None, logs warning
- Views are skipped; idempotent (safe to re-run)

Includes integration tests verifying:
- Happy path (index created, PK enforcement works)
- Failure path (duplicates → PK stripped, rows preserved)
- Composite PK with string columns (left() truncation)
- Multi-table migration (one succeeds, one fails independently)
- Idempotent re-run
- No-PK tables unaffected

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ine single-use helper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants