From 0aebb9351721d0963fcab05446c475f2414c0485 Mon Sep 17 00:00:00 2001 From: vincbeck Date: Mon, 22 Sep 2025 11:14:06 -0400 Subject: [PATCH] Update `dag_bundle_team.dag_bundle_name` type to match dag bundle table --- airflow-core/docs/img/airflow_erd.sha256 | 2 +- airflow-core/docs/migrations-ref.rst | 4 +- ..._add_length_dag_bundle_team_bundle_name.py | 58 +++++++++++++++++++ airflow-core/src/airflow/models/dagbundle.py | 2 +- airflow-core/src/airflow/models/team.py | 11 +++- 5 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 airflow-core/src/airflow/migrations/versions/0088_3_2_0_add_length_dag_bundle_team_bundle_name.py diff --git a/airflow-core/docs/img/airflow_erd.sha256 b/airflow-core/docs/img/airflow_erd.sha256 index fb970f63c5691..758bf88367dd5 100644 --- a/airflow-core/docs/img/airflow_erd.sha256 +++ b/airflow-core/docs/img/airflow_erd.sha256 @@ -1 +1 @@ -42a5f9219ef3dac4f12b20c3e11557c2aba2602e8f41c5858501ad5e5f82df7e \ No newline at end of file +290d11c38dc1b90c852ee03a4d5c11c078fe95de9667cede863e7ad30e19573f \ No newline at end of file diff --git a/airflow-core/docs/migrations-ref.rst b/airflow-core/docs/migrations-ref.rst index a08ceb1e58a9d..16a2a460d872d 100644 --- a/airflow-core/docs/migrations-ref.rst +++ b/airflow-core/docs/migrations-ref.rst @@ -39,7 +39,9 @@ Here's the list of all the Database Migrations that are executed via when you ru +-------------------------+------------------+-------------------+--------------------------------------------------------------+ | Revision ID | Revises ID | Airflow Version | Description | +=========================+==================+===================+==============================================================+ -| ``ab6dc0c82d0e`` (head) | ``15d84ca19038`` | ``3.2.0`` | Change ``serialized_dag`` data column to JSONB for | +| ``1b2c3d4e5f6g`` (head) | ``ab6dc0c82d0e`` | ``3.2.0`` | Add length to dag_bundle_team.dag_bundle_name. | ++-------------------------+------------------+-------------------+--------------------------------------------------------------+ +| ``ab6dc0c82d0e`` | ``15d84ca19038`` | ``3.2.0`` | Change ``serialized_dag`` data column to JSONB for | | | | | PostgreSQL. | +-------------------------+------------------+-------------------+--------------------------------------------------------------+ | ``15d84ca19038`` | ``cc92b33c6709`` | ``3.2.0`` | replace asset_trigger table with asset_watcher. | diff --git a/airflow-core/src/airflow/migrations/versions/0088_3_2_0_add_length_dag_bundle_team_bundle_name.py b/airflow-core/src/airflow/migrations/versions/0088_3_2_0_add_length_dag_bundle_team_bundle_name.py new file mode 100644 index 0000000000000..1fe9975ac00d3 --- /dev/null +++ b/airflow-core/src/airflow/migrations/versions/0088_3_2_0_add_length_dag_bundle_team_bundle_name.py @@ -0,0 +1,58 @@ +# +# 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 length to dag_bundle_team.dag_bundle_name. + +Revision ID: ab6dc0c82d0eg +Revises: ab6dc0c82d0e +Create Date: 2025-09-22 12:34:56.000000 + +""" + +from __future__ import annotations + +from alembic import op + +from airflow.migrations.db_types import StringID + +# revision identifiers, used by Alembic. +revision = "1b2c3d4e5f6g" +down_revision = "ab6dc0c82d0e" +branch_labels = None +depends_on = None +airflow_version = "3.2.0" + + +def upgrade(): + with op.batch_alter_table("dag_bundle_team") as batch_op: + batch_op.alter_column( + "dag_bundle_name", + type_=StringID(length=250), + existing_nullable=False, + ) + + +def downgrade(): + with op.batch_alter_table("dag_bundle_team") as batch_op: + # revert to plain StringID() without length (works on Postgres, fails on MySQL) + batch_op.alter_column( + "dag_bundle_name", + type_=StringID(), + existing_nullable=False, + ) diff --git a/airflow-core/src/airflow/models/dagbundle.py b/airflow-core/src/airflow/models/dagbundle.py index eb391b06db44e..91e3f97c402b3 100644 --- a/airflow-core/src/airflow/models/dagbundle.py +++ b/airflow-core/src/airflow/models/dagbundle.py @@ -42,7 +42,7 @@ class DagBundleModel(Base, LoggingMixin): """ __tablename__ = "dag_bundle" - name = Column(StringID(), primary_key=True, nullable=False) + name = Column(StringID(length=250), primary_key=True, nullable=False) active = Column(Boolean, default=True) version = Column(String(200), nullable=True) last_refreshed = Column(UtcDateTime, nullable=True) diff --git a/airflow-core/src/airflow/models/team.py b/airflow-core/src/airflow/models/team.py index 7609f3ff8b288..3ef31b434095a 100644 --- a/airflow-core/src/airflow/models/team.py +++ b/airflow-core/src/airflow/models/team.py @@ -24,7 +24,7 @@ from sqlalchemy.orm import relationship from sqlalchemy_utils import UUIDType -from airflow.models.base import Base +from airflow.models.base import Base, StringID from airflow.utils.session import NEW_SESSION, provide_session if TYPE_CHECKING: @@ -33,8 +33,13 @@ dag_bundle_team_association_table = Table( "dag_bundle_team", Base.metadata, - Column("dag_bundle_name", ForeignKey("dag_bundle.name", ondelete="CASCADE"), primary_key=True), - Column("team_id", ForeignKey("team.id", ondelete="CASCADE"), primary_key=True), + Column( + "dag_bundle_name", + StringID(length=250), + ForeignKey("dag_bundle.name", ondelete="CASCADE"), + primary_key=True, + ), + Column("team_id", UUIDType(binary=False), ForeignKey("team.id", ondelete="CASCADE"), primary_key=True), Index("idx_dag_bundle_team_dag_bundle_name", "dag_bundle_name", unique=True), Index("idx_dag_bundle_team_team_id", "team_id"), )