Skip to content

Conversation

@nielsreijers
Copy link
Contributor

@nielsreijers nielsreijers commented Jan 6, 2025

Fixes #77

  • Added handle_rename_table_query() in db_replicator.py to handle RENAME TABLE queries, possibly renaming multiple tables at once.

  • Refactored the code to split a table specifier in database and table name, map database name to target database when necessary, and check if the database and table match the config filter to a separate function since it was already duplicated for alter and delete queries, and the same code was necessary for table renames. Added advantage is that all places where it's used should now correctly strip the backticks, and check if the db/table match the config filter.

  • Moved the call to self.upload_records() from handle_alter_query() to handle_query_event() since inserts should be flushed before table rename, and probably before a delete as well since otherwise a delayed insert/update may be targeting a table that doesn't exist anymore.

  • Added a test, also for my previous PR

if self.config.debug_log_level:
logger.debug(f'processing query event: {event.transaction_id}, query: {event.records}')
query = strip_sql_comments(event.records)
self.upload_records()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too broad, it will be triggered even on unhandled event types. I propose to upload records only if one of ifs happend (line 480 - 487)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes you're right of course. :-) I changed it to upload for alter/delete/rename.

@bakwc
Copy link
Owner

bakwc commented Jan 6, 2025

Awesome! Thanks for the PR. Left one comment to address.

@bakwc bakwc merged commit fb8d88c into bakwc:master Jan 7, 2025
1 check passed
jaredmdobson pushed a commit to ReMatter/mysql_ch_replicator that referenced this pull request Nov 5, 2025
* Add unittest for "IF (NOT) EXISTS"

* Support Percona-style migration to add a column

* Review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Percona migrations

2 participants