-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix db clean command for mysql db #29999
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @dstandish = WDYT?
One NIT I'd add @tanvn is to add similar comment here as the one you referred in the issue:
so that we know where it came from |
bind = session.get_bind() | ||
dialect_name = bind.dialect.name | ||
if dialect_name == "mysql": | ||
session.execute(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session.execute(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}") | |
# MySQL with replication needs this split in to two queries, so just do it for all MySQL | |
# ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT. | |
session.execute(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I added the comment!
…vn/airflow into fix-db-clean-command-for-mysql
if dialect_name == "mysql": | ||
# MySQL with replication needs this split into two queries, so just do it for all MySQL | ||
# ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT. | ||
session.execute(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of writing custom SQL here, would it be better to enhance CreateTableAs
compilation to support the MySQL syntax instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uranusjr I would love to do so but I am new to sqlalchemy and at first I do not know how to let the compiler execute 2 queries instead of one?
(I just took a quick look at https://docs.sqlalchemy.org/en/20/core/compiler.html#dialect-specific-compilation-rules)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm good point. It’s probably possible with some SQL but likely not worthwhile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Awesome work, congrats on your first merged pull request! |
(cherry picked from commit 78cc2e8)
(cherry picked from commit 78cc2e8)
closes: #28051
Tested on my local environment (running with MySQL 8) and confirmed that it is working well.
This is my very first PR, so if there is anything else I should do (like adding new tests?), please let me know.