ephraimbuddy commented on code in PR #62234:
URL: https://github.com/apache/airflow/pull/62234#discussion_r2941539051
##########
airflow-core/src/airflow/migrations/utils.py:
##########
@@ -112,3 +113,196 @@ def ignore_sqlite_value_error():
if op.get_bind().dialect.name == "sqlite":
return contextlib.suppress(ValueError)
return contextlib.nullcontext()
+
+
+def get_dialect_name(op) -> str:
+ conn = op.get_bind()
+ return conn.dialect.name if conn is not None else
op.get_context().dialect.name
+
+
+def create_index_if_not_exists(op, index_name, table_name, columns,
unique=False) -> None:
+ """
+ Create an index if it does not already exist.
+
+ MySQL does not support CREATE INDEX IF NOT EXISTS, so a stored procedure
is used.
+ PostgreSQL and SQLite support it natively.
+ """
+ dialect_name = get_dialect_name(op)
+
+ if dialect_name == "mysql":
+ unique_kw = "UNIQUE " if unique else ""
+ col_list = ", ".join(f"`{c}`" for c in columns)
+ op.execute(
+ text(f"""
+ CREATE PROCEDURE CreateIndexIfNotExists()
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]