Fix record corruption when fields are reordered in table config#150
Merged
Fix record corruption when fields are reordered in table config#150
Conversation
Make tuple identity independent of the order fields are declared in the config. Previously, the position of each value within a row's primary-key or subsidiary tuple followed the declaration order in `tables.toml`, so swapping two fields in the config silently changed every record's hash key and produced bogus deltas against pre-swap state and blocks. Replace `compute_key_indices` with `compute_canonical_columns`, which sorts columns lexicographically by field name within each group and returns each entry paired with its `FieldConfig`. Bundling index and parser eliminates the implicit "two sorts must agree" coupling between indices and configs that the old layout had. SQL emission still follows the wire's column order, which is now canonical, so generated INSERT column lists and composite-PK WHERE clauses are emitted in lexicographic order — a follow-up will reroute SQL emission through the hub's declared order so users keep their preferred column ordering in generated SQL. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Tablerecords (both primary key and subsidiary halves) was tied to the declaration order of fields intables.toml. Swapping two fields in the config silently changed every row's hash key, breaking delta merging against pre-swap state and historical blocks.compute_canonical_columnsreturns each tuple slot as a(column_index, &FieldConfig)pair, so the index and parser can't drift;parse_columnsconsumes the bundled slice directly.Notes for reviewers
accept_composite_pk.rshad its expected SQL updated to reflect the canonical column order (course_idbeforestudent_id). The follow-up that reroutes SQL emission will flip these assertions back.Delta::compute/merge_block_deltasand fall back to a full state payload, so no migration code is needed.