Skip to content

Commit 3a8edc0

Browse files
committed
fix: handle old shards with extra columns during reassemble
When schema removes columns (summary_format_version, old_summary), old shards still have them. _migrate_shard_schema now also DROPs columns from the shard that main no longer has, so INSERT ... SELECT * doesn't fail with column-count mismatch.
1 parent 817270f commit 3a8edc0

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/data/sharder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,17 @@ def _migrate_shard_schema(target: sqlite3.Connection) -> None:
559559
migrate = PPT_PAGES_MIGRATION_COLUMNS
560560
else:
561561
migrate = []
562+
# Add columns that main has but shard is missing.
562563
for col, typedef in migrate:
563564
if col in main_cols and col not in shard_cols:
564565
target.execute(
565566
f"ALTER TABLE shard.{table} ADD COLUMN {col} {typedef}"
566567
)
568+
# Drop columns that shard has but main no longer has (schema
569+
# evolution — e.g. ``summary_format_version``, ``old_summary``).
570+
extra_cols = shard_cols - main_cols
571+
for col in extra_cols:
572+
target.execute(f"ALTER TABLE shard.{table} DROP COLUMN {col}")
567573

568574

569575
def reassemble_database(

0 commit comments

Comments
 (0)