ashb commented on code in PR #24044:
URL: https://github.com/apache/airflow/pull/24044#discussion_r901549702


##########
airflow/migrations/versions/0112_2_4_0_compare_types_between_orm_and_db.py:
##########
@@ -0,0 +1,267 @@
+#
+# 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.
+
+"""compare types between ORM and DB
+
+Revision ID: 44b7034f6bdc
+Revises: 3c94c427fdf6
+Create Date: 2022-05-31 09:16:44.558754
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+from airflow.migrations.db_types import TIMESTAMP
+
+# revision identifiers, used by Alembic.
+revision = '44b7034f6bdc'
+down_revision = 'f5fcbda3e651'
+branch_labels = None
+depends_on = None
+airflow_version = '2.4.0'
+
+
+def upgrade():
+    """Apply compare types between ORM and DB"""
+    conn = op.get_bind()
+    with op.batch_alter_table('connection', schema=None) as batch_op:
+        batch_op.alter_column(
+            'extra',
+            existing_type=sa.TEXT(),
+            type_=sa.Text(),
+            existing_nullable=True,
+        )
+    with op.batch_alter_table('log_template', schema=None) as batch_op:
+        batch_op.alter_column(
+            'created_at', existing_type=sa.DateTime(), type_=TIMESTAMP(), 
existing_nullable=False
+        )
+    with op.batch_alter_table('task_instance', schema=None) as batch_op:
+        batch_op.alter_column(
+            'trigger_timeout', existing_type=sa.DateTime(), type_=TIMESTAMP(), 
existing_nullable=True

Review Comment:
   We need to test how long this takes on a huge TI table please.



##########
airflow/migrations/versions/0112_2_4_0_compare_types_between_orm_and_db.py:
##########
@@ -0,0 +1,267 @@
+#
+# 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.
+
+"""compare types between ORM and DB
+
+Revision ID: 44b7034f6bdc
+Revises: 3c94c427fdf6
+Create Date: 2022-05-31 09:16:44.558754
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+from airflow.migrations.db_types import TIMESTAMP
+
+# revision identifiers, used by Alembic.
+revision = '44b7034f6bdc'
+down_revision = 'f5fcbda3e651'
+branch_labels = None
+depends_on = None
+airflow_version = '2.4.0'
+
+
+def upgrade():
+    """Apply compare types between ORM and DB"""
+    conn = op.get_bind()
+    with op.batch_alter_table('connection', schema=None) as batch_op:
+        batch_op.alter_column(
+            'extra',
+            existing_type=sa.TEXT(),
+            type_=sa.Text(),

Review Comment:
   What effect does this actually have? It seems like a no-op.



##########
airflow/migrations/versions/0112_2_4_0_compare_types_between_orm_and_db.py:
##########
@@ -0,0 +1,267 @@
+#
+# 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.
+
+"""compare types between ORM and DB
+
+Revision ID: 44b7034f6bdc
+Revises: 3c94c427fdf6
+Create Date: 2022-05-31 09:16:44.558754
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+from airflow.migrations.db_types import TIMESTAMP
+
+# revision identifiers, used by Alembic.
+revision = '44b7034f6bdc'
+down_revision = 'f5fcbda3e651'
+branch_labels = None
+depends_on = None
+airflow_version = '2.4.0'
+
+
+def upgrade():
+    """Apply compare types between ORM and DB"""
+    conn = op.get_bind()
+    with op.batch_alter_table('connection', schema=None) as batch_op:
+        batch_op.alter_column(
+            'extra',
+            existing_type=sa.TEXT(),
+            type_=sa.Text(),
+            existing_nullable=True,
+        )
+    with op.batch_alter_table('log_template', schema=None) as batch_op:
+        batch_op.alter_column(
+            'created_at', existing_type=sa.DateTime(), type_=TIMESTAMP(), 
existing_nullable=False
+        )
+    with op.batch_alter_table('task_instance', schema=None) as batch_op:
+        batch_op.alter_column(
+            'trigger_timeout', existing_type=sa.DateTime(), type_=TIMESTAMP(), 
existing_nullable=True
+        )
+    with op.batch_alter_table('serialized_dag', schema=None) as batch_op:
+        # drop server_default
+        batch_op.alter_column(
+            'dag_hash',
+            existing_type=sa.String(32),
+            server_default=None,
+            type_=sa.String(32),
+            existing_nullable=False,
+        )
+    with op.batch_alter_table('trigger', schema=None) as batch_op:
+        batch_op.alter_column(
+            'created_date', existing_type=sa.DateTime(), type_=TIMESTAMP(), 
existing_nullable=False
+        )
+    # pool_slots server_default mistakenly dropped in 7b2661a43ba3 for 
postgresql.
+    # existing_server_default not used in alter
+    if conn.dialect.name == 'postgresql':
+        with op.batch_alter_table('task_instance', schema=None) as batch_op:
+            batch_op.alter_column(
+                'pool_slots', existing_type=sa.Integer(), 
server_default=sa.text('1'), existing_nullable=False

Review Comment:
   Ditto here: How long does this take?
   
   This default value was only actually needed for the migration where we added 
the column in the first place -- now that it exists and all existing rows are 
populated with a value this server default is never used.
   
   If this is AT ALL expensive to do just change the model here.



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

Reply via email to