jedcunningham commented on code in PR #44533: URL: https://github.com/apache/airflow/pull/44533#discussion_r1872246276
########## airflow/migrations/versions/0050_3_0_0_remove_pickled_data_from_dagrun_table.py: ########## @@ -0,0 +1,118 @@ +# +# 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. + +""" +remove pickled data from dagrun table. + +Revision ID: e39a26ac59f6 +Revises: eed27faa34e3 +Create Date: 2024-12-01 08:33:15.425141 + +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op +from sqlalchemy import text +from sqlalchemy.dialects.mysql import LONGBLOB + +# revision identifiers, used by Alembic. +revision = "e39a26ac59f6" +down_revision = "eed27faa34e3" +branch_labels = None +depends_on = None +airflow_version = "3.0.0" + + +def upgrade(): + """Apply remove pickled data from dagrun table.""" + # Summary of the change: + # 1. Updating dag_run.conf column value to NULL. + # 2. Update the dag_run.conf column type to JSON from bytea + + conn = op.get_bind() + dialect = conn.dialect.name + + # Update the dag_run.conf column value to NULL + conn.execute(text("UPDATE dag_run set conf=null WHERE conf IS NOT NULL")) Review Comment: This just gets rid of all of the values? They may not all be pickled, right? ########## airflow/migrations/versions/0050_3_0_0_remove_pickled_data_from_dagrun_table.py: ########## @@ -0,0 +1,118 @@ +# +# 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. + +""" +remove pickled data from dagrun table. + +Revision ID: e39a26ac59f6 +Revises: eed27faa34e3 +Create Date: 2024-12-01 08:33:15.425141 + +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op +from sqlalchemy import text +from sqlalchemy.dialects.mysql import LONGBLOB + +# revision identifiers, used by Alembic. +revision = "e39a26ac59f6" +down_revision = "eed27faa34e3" +branch_labels = None +depends_on = None +airflow_version = "3.0.0" + + +def upgrade(): + """Apply remove pickled data from dagrun table.""" + # Summary of the change: + # 1. Updating dag_run.conf column value to NULL. + # 2. Update the dag_run.conf column type to JSON from bytea + + conn = op.get_bind() + dialect = conn.dialect.name + + # Update the dag_run.conf column value to NULL + conn.execute(text("UPDATE dag_run set conf=null WHERE conf IS NOT NULL")) + + # Update the conf column type to JSON + if dialect == "postgresql": + op.execute( + """ + ALTER TABLE dag_run + ALTER COLUMN conf TYPE JSONB + USING CASE + WHEN conf IS NOT NULL THEN CAST(CONVERT_FROM(conf, 'UTF8') AS JSONB) + ELSE NULL + END + """ + ) + elif dialect == "mysql": Review Comment: And for mysql/sqlite, even if we had data, we don't move any of it from the old to new column. -- 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]
