You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/02/14 13:41:47 UTC

[GitHub] [airflow] ashb commented on a change in pull request #21462: Create migrations for new DBs from the ORM

ashb commented on a change in pull request #21462:
URL: https://github.com/apache/airflow/pull/21462#discussion_r805852106



##########
File path: airflow/models/taskinstance.py
##########
@@ -2326,6 +2327,35 @@ def filter_for_tis(tis: Iterable[Union["TaskInstance", TaskInstanceKey]]) -> Opt
             ).in_([ti.key.primary for ti in tis])
 
 
+@event.listens_for(TaskInstance.__table__, "after_create")
+def add_index_taskinstance_mysql(*arg, **kw):
+    """Add an index for mysql"""
+    return CreateIndex(
+        Index(
+            'ti_map_index',
+            TaskInstance.__table__.c.dag_id,
+            TaskInstance.__table__.c.task_id,
+            TaskInstance.__table__.c.run_id,
+            TaskInstance.__table__.c.map_index,
+        )
+    ).execute_if(dialect='mysql')(*arg, **kw)
+
+
+@event.listens_for(TaskInstance.__table__, "after_create")
+def add_index_taskinstance_mssql(*arg, **kw):
+    """Add unique index for mssql"""
+    return CreateIndex(
+        Index(
+            'ti_map_index',
+            TaskInstance.__table__.c.dag_id,
+            TaskInstance.__table__.c.task_id,
+            TaskInstance.__table__.c.run_id,
+            TaskInstance.__table__.c.map_index,
+            unique=True,
+        )
+    ).execute_if(dialect='mssql')(*arg, **kw)

Review comment:
       https://docs.sqlalchemy.org/en/14/core/ddl.html#sqlalchemy.schema.DDLElement.execute_if.params.dialect
   
   `DDL('something').execute_if(dialect=('postgresql', 'mysql'))`




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org