Skip to content

Commit

Permalink
Merge pull request #5 from sendbird/develop
Browse files Browse the repository at this point in the history
Add migration_id to DELETE unmatched_rows query
  • Loading branch information
jjh-kim authored Jun 3, 2024
2 parents a7e9ccb + b585632 commit ba0bcf1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/sbosc/controller/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def setup_database(self):
source_pk bigint,
migration_id int,
unmatch_type varchar(128),
KEY `idx_unmatched_rows_migration_id` (`migration_id`)
KEY `idx_unmatched_rows_migration_id_source_pk` (`migration_id`, `source_pk`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
''')
self.logger.info("Unmatched rows table created")
Expand Down
4 changes: 2 additions & 2 deletions src/sbosc/controller/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def validate_unmatched_pks(self):
matched_pks_str = ','.join([str(pk) for pk in matched_pks])
cursor.execute(f'''
DELETE FROM {config.SBOSC_DB}.unmatched_rows WHERE source_pk IN ({matched_pks_str})
AND unmatch_type = '{UnmatchType.NOT_UPDATED}'
AND unmatch_type = '{UnmatchType.NOT_UPDATED}' AND migration_id = {self.migration_id}
''')
if len(not_removed_pks) > 0:
matched_pks = self.migration_operation.get_rematched_removed_pks(self.db, not_removed_pks)
Expand All @@ -250,7 +250,7 @@ def validate_unmatched_pks(self):
matched_pks_str = ','.join([str(pk) for pk in matched_pks])
cursor.execute(f'''
DELETE FROM {config.SBOSC_DB}.unmatched_rows WHERE source_pk IN ({matched_pks_str})
AND unmatch_type = '{UnmatchType.NOT_REMOVED}'
AND unmatch_type = '{UnmatchType.NOT_REMOVED}' AND migration_id = {self.migration_id}
''')
self.redis_data.updated_pk_set.add(not_updated_pks - not_removed_pks)
self.redis_data.updated_pk_set.remove(not_removed_pks)
Expand Down
4 changes: 2 additions & 2 deletions src/sbosc/operations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_rematched_removed_pks(self, db, not_removed_pks):
SELECT source_pk FROM {config.SBOSC_DB}.unmatched_rows WHERE source_pk NOT IN (
SELECT id FROM {self.destination_db}.{self.destination_table}
WHERE id IN ({not_removed_pks_str})
) AND source_pk IN ({not_removed_pks_str})
) AND source_pk IN ({not_removed_pks_str}) AND migration_id = {self.migration_id}
''')
rematched_pks = set([row[0] for row in cursor.fetchall()])
# add reinserted pks
Expand Down Expand Up @@ -268,7 +268,7 @@ def get_rematched_removed_pks(self, db, not_removed_pks):
cursor: Cursor
query = f'''
SELECT source_pk FROM {config.SBOSC_DB}.unmatched_rows
WHERE source_pk IN ({not_removed_pks_str})
WHERE source_pk IN ({not_removed_pks_str}) AND migration_id = {self.migration_id}
'''
if still_not_removed_pks_str:
query += f" AND source_pk NOT IN ({still_not_removed_pks_str})"
Expand Down

0 comments on commit ba0bcf1

Please sign in to comment.