[PXT-477] Add migration for existing primary key tables - #4
Open
Chrisclone wants to merge 1 commit into
Open
Conversation
…bles When upgrading from schema version 48 to 49, existing tables with is_pk=True columns but no primary_index_md get a PrimaryIndexMd generated and a physical partial unique index created. If index creation fails due to duplicate live rows, is_pk is stripped from all columns to preserve data without silent deduplication. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migration Strategy for Existing Primary Key Tables
Implements the migration path for tables created with
primary_keycolumns before the PK enforcement PR.Problem
PR pixeltable#1203 adds a partial unique B-tree index for new tables, but existing tables with
is_pk=Truecolumns have:PrimaryIndexMdin their metadataSolution: Schema Version 48 → 49
Converter
convert_48.pyruns during catalog load and for each base table with PK columns but no index:PrimaryIndexMd(matchingcreate_initial_md()logic)CREATE UNIQUE INDEXinside a savepointprimary_index_md, PK enforcement is activeis_pkfrom all columns, logs warning:Design Decisions
left(col, 256)truncation matchingBtreeIndex.MAX_STRING_LENprimary_index_md is Nonebefore runningFiles
pixeltable/metadata/converters/convert_48.py— migration logicpixeltable/metadata/__init__.py— version bump 48 → 49pixeltable/metadata/notes.py— version notetests/test_pk_migration.py— 4 test cases (happy path, duplicates, composite PK, idempotency)Generated by OpenClaw