fix: Mark migration as completed when migration finishes

The _update_migration_state() method was using logic:
  status = "in_progress" if last_id is not None else "completed"

This was incorrect because:
1. last_id is always set during periodic updates (to track resume point)
2. So status would always be "in_progress" even when migration finished
3. migration_completed_at would never be set

Solution: Add is_final parameter to explicitly mark when migration is
complete. During periodic updates, is_final=False (status="in_progress").
Only when called at the end, is_final=True (status="completed").

This ensures:
- migration_state.status = "completed" when done
- migration_state.migration_completed_at is set
- Proper tracking for knowing if migration is finished

🤖 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 20:41:46 +01:00
parent 8d9e63081a
commit d3ada1ded2

View File

@@ -179,7 +179,7 @@ class FullMigrator:
logger.info(f"About to update migration_state with count={final_count}, last_id={final_last_id}") logger.info(f"About to update migration_state with count={final_count}, last_id={final_last_id}")
self._update_migration_state( self._update_migration_state(
pg_conn, final_count, final_last_id, migration_start_time pg_conn, final_count, final_last_id, migration_start_time, is_final=True
) )
logger.info(f"Migration state update complete") logger.info(f"Migration state update complete")
@@ -244,7 +244,8 @@ class FullMigrator:
pg_conn: PostgreSQLConnector, pg_conn: PostgreSQLConnector,
rows_migrated: int, rows_migrated: int,
last_id: Optional[int] = None, last_id: Optional[int] = None,
migration_start_time: Optional[str] = None migration_start_time: Optional[str] = None,
is_final: bool = False
) -> None: ) -> None:
"""Update migration state in PostgreSQL and state file. """Update migration state in PostgreSQL and state file.
@@ -253,10 +254,11 @@ class FullMigrator:
rows_migrated: Total number of rows migrated so far rows_migrated: Total number of rows migrated so far
last_id: Last ID that was migrated (for resume capability) last_id: Last ID that was migrated (for resume capability)
migration_start_time: When the migration started (ISO format) migration_start_time: When the migration started (ISO format)
is_final: If True, mark migration as completed
""" """
pg_table = self.config["postgres_table"] pg_table = self.config["postgres_table"]
now = datetime.utcnow() now = datetime.utcnow()
status = "in_progress" if last_id is not None else "completed" status = "completed" if is_final else "in_progress"
# Update PostgreSQL migration_state table # Update PostgreSQL migration_state table
try: try: