From 1708969616f6097f4a614e7a8cde58e937e429c0 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 23 Dec 2025 20:16:28 +0100 Subject: [PATCH] fix: Update migration state with final count when migration completes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/migrator/full_migration.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/migrator/full_migration.py b/src/migrator/full_migration.py index 7563795..426161e 100644 --- a/src/migrator/full_migration.py +++ b/src/migrator/full_migration.py @@ -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}" )