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/03/07 21:32:22 UTC

[GitHub] [airflow] ashb commented on a change in pull request #22004: Add map_index to RenderedTaskInstanceFields

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



##########
File path: airflow/migrations/versions/4eaab2fe6582_migrate_rtif_to_use_run_id_and_map_index.py
##########
@@ -0,0 +1,190 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Migrate RTIF to use run_id and map_index
+
+Revision ID: 4eaab2fe6582
+Revises: c306b5b5ae4a
+Create Date: 2022-03-03 17:48:29.955821
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.sql import and_, select
+from sqlalchemy.sql.schema import ForeignKeyConstraint
+
+from airflow.migrations.db_types import TIMESTAMP, StringID
+
+ID_LEN = 250
+
+# revision identifiers, used by Alembic.
+revision = '4eaab2fe6582'
+down_revision = 'c306b5b5ae4a'
+branch_labels = None
+depends_on = None
+airflow_version = '2.3.0'
+
+
+# Just Enough Table to run the conditions for update.
+def tables(for_downgrade=False):
+    import sqlalchemy_jsonfield
+
+    global task_instance, rendered_task_instance_fields, dag_run
+    metadata = sa.MetaData()
+    task_instance = sa.Table(
+        'task_instance',
+        metadata,
+        sa.Column('task_id', StringID()),
+        sa.Column('dag_id', StringID()),
+        sa.Column('run_id', StringID()),
+        sa.Column('execution_date', TIMESTAMP),
+    )
+    rendered_task_instance_fields = sa.Table(
+        'rendered_task_instance_fields',
+        metadata,
+        sa.Column('task_id', StringID()),
+        sa.Column('dag_id', StringID()),
+        sa.Column('run_id', StringID()),
+        sa.Column('execution_date', TIMESTAMP),
+        sa.Column('rendered_fields', sqlalchemy_jsonfield.JSONField(), nullable=False),
+        sa.Column('k8s_pod_yaml', sqlalchemy_jsonfield.JSONField(), nullable=True),
+    )
+
+    if for_downgrade:
+        rendered_task_instance_fields.append_column(
+            sa.Column('map_index', sa.Integer(), server_default='-1'),
+        )
+        rendered_task_instance_fields.append_constraint(
+            ForeignKeyConstraint(
+                ['dag_id', 'run_id'],
+                ["dag_run.dag_id", "dag_run.run_id"],
+                name='rtif_dag_run_fkey',
+                ondelete="CASCADE",
+            ),
+        )
+    dag_run = sa.Table(
+        'dag_run',
+        metadata,
+        sa.Column('dag_id', StringID()),
+        sa.Column('run_id', StringID()),
+        sa.Column('execution_date', TIMESTAMP),
+    )
+
+
+def get_table_constraints(conn, table_name):

Review comment:
       Ah cool.




-- 
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