kaxil commented on a change in pull request #6788: WIP: [AIRFLOW-5944] 
Rendering templated_fields without accessing DAG files
URL: https://github.com/apache/airflow/pull/6788#discussion_r373608085
 
 

 ##########
 File path: 
airflow/migrations/versions/852ae6c715af_add_templated_fields_rendered_table.py
 ##########
 @@ -0,0 +1,103 @@
+#
+# 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.
+
+"""Add TemplatedFieldsRendered table
+
+Revision ID: 852ae6c715af
+Revises: 1d3a23a719bf
+Create Date: 2019-12-10 22:19:18.034961
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.dialects import mysql
+
+# revision identifiers, used by Alembic.
+revision = '852ae6c715af'
+down_revision = '1d3a23a719bf'
+branch_labels = None
+depends_on = None
+
+TABLE_NAME = 'templated_fields_rendered'
+INDEX_NAME = 'idx_tfr_dag_task_date'
+
+
+def upgrade():
+    """Apply Add TemplatedFieldsRendered table"""
+    json_type = sa.JSON
+    conn = op.get_bind()  # pylint: disable=no-member
+
+    if conn.dialect.name != "postgresql":
+        # Mysql 5.7+/MariaDB 10.2.3 has JSON support. Rather than checking for
+        # versions, check for the function existing.
+        try:
+            conn.execute("SELECT JSON_VALID(1)").fetchone()
+        except sa.exc.OperationalError:
+            json_type = sa.Text
+
+    op.create_table(
+        TABLE_NAME,  # pylint: disable=no-member
+        sa.Column('dag_id', sa.String(length=250), nullable=False),
+        sa.Column('task_id', sa.String(length=250), nullable=False),
+        sa.Column('execution_date', sa.DateTime(), nullable=False),
+        sa.Column('rendered_fields', json_type(), nullable=True),
+        sa.PrimaryKeyConstraint('dag_id', 'task_id', 'execution_date')
+    )
+    op.create_index(  # pylint: disable=no-member
+        INDEX_NAME,
+        TABLE_NAME,
+        ['dag_id', 'task_id', 'execution_date'],
+    )
+
+    if conn.dialect.name == "mysql":
+        conn.execute("SET time_zone = '+00:00'")
 
 Review comment:
   From the same 
[article](https://www.eversql.com/mysql-datetime-vs-timestamp-column-types-which-one-i-should-use/)
 :
   
   >To summarize, if you want to serve your date and time data the same way 
regardless of timezones, you can use the DATETIME type (which will also allow 
you to use all the date & type functions built in MySQL). Otherwise, you can 
use TIMESTAMP and serve the data on a per-timezone basis.
   
   Also, from 
https://docs.sqlalchemy.org/en/13/core/type_basics.html#sqlalchemy.types.DateTime
   >For timezone support, use at least the TIMESTAMP datatype, if not the 
dialect-specific datatype object.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to