fix: Use correct ID column for ELABDATADISP in fetch_rows_ordered_for_consolidation()

ELABDATADISP uses 'idElabData' as the primary key, while RAWDATACOR uses 'id'.
Updated the fetch method to detect the correct column based on the table name:
- RAWDATACOR: use 'id' column
- ELABDATADISP: use 'idElabData' column

This allows keyset pagination to work correctly for both tables.

Fixes: "Unknown column 'id' in 'order clause'" error when fetching ELABDATADISP

🤖 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-25 19:04:51 +01:00
parent e75cf4c545
commit 3c0a6f72b4

View File

@@ -244,6 +244,9 @@ class MySQLConnector:
if batch_size is None:
batch_size = self.settings.migration.batch_size
# Determine the ID column name based on table
id_column = "idElabData" if table == "ELABDATADISP" else "id"
last_id = start_id
max_retries = 3
@@ -255,10 +258,10 @@ class MySQLConnector:
# Use keyset pagination: fetch by id > last_id
# This is much more efficient than OFFSET for large tables
if last_id is None:
query = f"SELECT * FROM `{table}` ORDER BY `id` ASC LIMIT %s"
query = f"SELECT * FROM `{table}` ORDER BY `{id_column}` ASC LIMIT %s"
cursor.execute(query, (batch_size,))
else:
query = f"SELECT * FROM `{table}` WHERE `id` > %s ORDER BY `id` ASC LIMIT %s"
query = f"SELECT * FROM `{table}` WHERE `{id_column}` > %s ORDER BY `{id_column}` ASC LIMIT %s"
cursor.execute(query, (last_id, batch_size))
rows = cursor.fetchall()
@@ -267,7 +270,7 @@ class MySQLConnector:
return
yield rows
last_id = rows[-1]["id"]
last_id = rows[-1][id_column]
break # Success, exit retry loop
except pymysql.Error as e: