fix: Update migration state with final count when migration completes
When migration finishes, we need to update migration_state with: 1. The final actual row count from PostgreSQL 2. The final last_migrated_id (MAX(id) from the table) 3. Mark status as 'completed' (handled by _update_migration_state) Previously, the final state update was missing, so migration_state was left with stale data from the periodic updates. Now _update_migration_state is called at the end to record the authoritative final state. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -161,6 +161,23 @@ class FullMigrator:
|
||||
|
||||
# Get final actual count from PostgreSQL
|
||||
final_count = pg_conn.get_row_count(pg_table)
|
||||
|
||||
# Update migration state with final count and mark as completed
|
||||
# Get the actual last ID from the table
|
||||
try:
|
||||
with pg_conn.connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
f"SELECT MAX(id) FROM {pg_table}"
|
||||
)
|
||||
result = cursor.fetchone()
|
||||
final_last_id = result[0] if result and result[0] else None
|
||||
except Exception:
|
||||
final_last_id = None
|
||||
|
||||
self._update_migration_state(
|
||||
pg_conn, final_count, final_last_id, migration_start_time
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"✓ Migration complete: {final_count} total rows in {pg_table}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user