fix: Use actual PostgreSQL row count for total_rows_migrated tracking

Replace session-level counting with direct table COUNT queries to ensure
total_rows_migrated always reflects actual reality in PostgreSQL. This fixes
the discrepancy where the counter was only tracking rows from the current session
and didn't account for earlier insertions or duplicates from failed resume attempts.

Key improvements:
- Use get_row_count() after each batch to get authoritative total
- Preserve previous count on resume and accumulate across sessions
- Remove dependency on error-prone session-level counters
- Ensures migration_state.total_rows_migrated matches actual table row count

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-23 15:33:27 +01:00
parent b09cfcf9df
commit 0f217379ea
8 changed files with 646 additions and 100 deletions

View File

@@ -69,7 +69,12 @@ def migrate():
is_flag=True,
help="Show what would be done without modifying data"
)
def full(table, dry_run):
@click.option(
"--resume",
is_flag=True,
help="Resume from last checkpoint if migration was interrupted"
)
def full(table, dry_run, resume):
"""Perform full migration of all data."""
setup_logger(__name__)
@@ -80,7 +85,7 @@ def full(table, dry_run):
for tbl in tables:
click.echo(f"\nMigrating {tbl}...")
migrated = run_full_migration(tbl, dry_run=dry_run)
migrated = run_full_migration(tbl, dry_run=dry_run, resume=resume)
total_migrated += migrated
click.echo(f"{tbl}: {migrated} rows migrated")