vincbeck commented on code in PR #53946:
URL: https://github.com/apache/airflow/pull/53946#discussion_r2245612271


##########
airflow-core/src/airflow/migrations/versions/0080_3_1_0_add_teams.py:
##########
@@ -0,0 +1,101 @@
+#
+# 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 tables to store teams and associations with dag bundles.
+
+Update also `connection`, `variable` and `pool` tables to add `team_id` as 
column.
+
+Revision ID: a3c7f2b18d4e
+Revises: f56f68b9e02f
+Create Date: 2025-07-30 15:46:40.122517
+
+"""
+
+from __future__ import annotations
+
+import sqlalchemy as sa
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "a3c7f2b18d4e"
+down_revision = "f56f68b9e02f"
+branch_labels = None
+depends_on = None
+airflow_version = "3.1.0"
+
+
+def upgrade():
+    """Create team table."""
+    op.create_table(
+        "team",

Review Comment:
   I hesitated between the 2. I do not think it matters that teams ids are 
predictable. I tend to use uuid when I know the number of records can be high, 
which should not be the case here. But I am not strongly opinionated, if you 
(and/or others?) prefer a uuid, we can use a uuid



##########
airflow-core/src/airflow/models/team.py:
##########
@@ -0,0 +1,51 @@
+#
+# 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.
+from __future__ import annotations
+
+from sqlalchemy import Column, ForeignKey, Index, Integer, String, Table
+from sqlalchemy.orm import relationship
+
+from airflow.models.base import Base
+
+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),
+    Index("idx_dag_bundle_team_dag_bundle_name", "dag_bundle_name", 
unique=True),
+    Index("idx_dag_bundle_team_team_id", "team_id"),
+)
+
+
+class Team(Base):
+    """
+    Contains the list of teams defined in the environment.
+
+    This table is only used when Airflow is run in multi-team mode.
+    """
+
+    __tablename__ = "team"
+
+    id = Column(Integer, primary_key=True)
+    name = Column(String(250), unique=True)
+    dag_bundles = relationship(
+        "DagBundleModel", secondary=dag_bundle_team_association_table, 
back_populates="teams"
+    )
+
+    def __repr__(self):
+        return f"Team {self.id}"

Review Comment:
   Makes sense



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