From 3c0a6f72b4b34caff4de33ce33bbaa0da092d62b Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 25 Dec 2025 19:04:51 +0100 Subject: [PATCH] fix: Use correct ID column for ELABDATADISP in fetch_rows_ordered_for_consolidation() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/connectors/mysql_connector.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/connectors/mysql_connector.py b/src/connectors/mysql_connector.py index e29c368..f94341a 100644 --- a/src/connectors/mysql_connector.py +++ b/src/connectors/mysql_connector.py @@ -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: