ashb commented on code in PR #24044: URL: https://github.com/apache/airflow/pull/24044#discussion_r885849674
########## airflow/migrations/versions/0111_2_3_3_compare_types_between_orm_and_db.py: ########## @@ -0,0 +1,79 @@ +# +# 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 = '3c94c427fdf6' +branch_labels = None +depends_on = None +airflow_version = '2.3.3' + + +def upgrade(): + """Apply compare types between ORM and DB""" + conn = op.get_bind() + 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('trigger', schema=None) as batch_op: + batch_op.alter_column( + 'created_date', existing_type=sa.DateTime(), type_=TIMESTAMP(), existing_nullable=False Review Comment: I'm not sure this one is right. Dateatime feels like the better type here That said I'm not 100% sure on the difference between the two ########## airflow/models/dagpickle.py: ########## @@ -39,7 +39,7 @@ class DagPickle(Base): id = Column(Integer, primary_key=True) pickle = Column(PickleType(pickler=dill)) created_dttm = Column(UtcDateTime, default=timezone.utcnow) - pickle_hash = Column(Text) + pickle_hash = Column(BIGINT) Review Comment: Have you checked what value we right on this column? ########## airflow/models/serialized_dag.py: ########## @@ -67,11 +67,11 @@ class SerializedDagModel(Base): dag_id = Column(String(ID_LEN), primary_key=True) fileloc = Column(String(2000), nullable=False) # The max length of fileloc exceeds the limit of indexing. - fileloc_hash = Column(BigInteger, nullable=False) + fileloc_hash = Column(BigInteger().with_variant(Integer, 'sqlite'), nullable=False) _data = Column('data', sqlalchemy_jsonfield.JSONField(json=json), nullable=True) _data_compressed = Column('data_compressed', LargeBinary, nullable=True) last_updated = Column(UtcDateTime, nullable=False) - dag_hash = Column(String(32), nullable=False) + dag_hash = Column(String(32), nullable=False, server_default='Hash not calculated yet') Review Comment: This is not nullable - why have you added a server default? -- 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]
