@@ -43,9 +43,9 @@ def get_max_pk(self, db, start_pk, end_pk):
4343 with db .cursor (host = 'dest' ) as cursor :
4444 cursor : Cursor
4545 cursor .execute (f'''
46- SELECT MAX({ self .pk_column } ) FROM { metadata .destination_db } .{ metadata .destination_table }
47- WHERE { self .pk_column } BETWEEN { start_pk } AND { end_pk }
48- ''' )
46+ SELECT MAX({ self .pk_column } ) FROM { metadata .destination_db } .{ metadata .destination_table }
47+ WHERE { self .pk_column } BETWEEN { start_pk } AND { end_pk }
48+ ''' )
4949 return cursor .fetchone ()[0 ]
5050
5151 def _get_not_imported_pks_query (self , start_pk , end_pk ):
@@ -196,21 +196,23 @@ def get_max_pk(self, db, start_pk, end_pk):
196196 with db .cursor (host = 'dest' ) as cursor :
197197 cursor : Cursor
198198 cursor .execute (f'''
199- SELECT MAX({ self .pk_column } ) FROM { metadata .destination_db } .{ metadata .destination_table }
200- WHERE { self .pk_column } BETWEEN { start_pk } AND { end_pk }
201- ''' )
199+ SELECT MAX({ self .pk_column } ) FROM { metadata .destination_db } .{ metadata .destination_table }
200+ WHERE { self .pk_column } BETWEEN { start_pk } AND { end_pk }
201+ ''' )
202202 return cursor .fetchone ()[0 ]
203203
204- def get_not_imported_pks (self , source_cursor , dest_cursor , start_pk , end_pk ):
205- source_cursor . execute ( f'''
206- SELECT { self .pk_column } FROM { self . source_db } . { self . source_table }
204+ def _get_not_imported_pks_query (self , table , start_pk , end_pk ):
205+ return f'''
206+ SELECT { self .pk_column } FROM { table } AS source
207207 WHERE { self .pk_column } BETWEEN { start_pk } AND { end_pk }
208- ''' )
208+ '''
209+
210+ def get_not_imported_pks (self , source_cursor , dest_cursor , start_pk , end_pk ):
211+ source_cursor .execute (
212+ self ._get_not_imported_pks_query (f'{ self .source_db } .{ self .source_table } ' , start_pk , end_pk ))
209213 source_pks = [row [0 ] for row in source_cursor .fetchall ()]
210- dest_cursor .execute (f'''
211- SELECT { self .pk_column } FROM { self .destination_db } .{ self .destination_table }
212- WHERE { self .pk_column } BETWEEN { start_pk } AND { end_pk }
213- ''' )
214+ dest_cursor .execute (
215+ self ._get_not_imported_pks_query (f'{ self .destination_db } .{ self .destination_table } ' , start_pk , end_pk ))
214216 dest_pks = [row [0 ] for row in dest_cursor .fetchall ()]
215217 return list (set (source_pks ) - set (dest_pks ))
216218
0 commit comments