vincbeck commented on code in PR #57464: URL: https://github.com/apache/airflow/pull/57464#discussion_r2473536601
########## airflow-core/src/airflow/migrations/versions/0092_3_2_0_ui_improvements_for_deadlines.py: ########## @@ -0,0 +1,113 @@ +# +# 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 required fields to enable UI integrations for the Deadline Alerts feature. + +Revision ID: 55297ae24532 +Revises: b87d2135fa50 +Create Date: 2025-10-17 16:04:55.016272 +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op +from sqlalchemy_utils import UUIDType + +from airflow.migrations.db_types import TIMESTAMP + +revision = "55297ae24532" +down_revision = "b87d2135fa50" +branch_labels = None +depends_on = None +airflow_version = "3.2.0" + + +def upgrade(): + """Make changes to enable adding DeadlineAlerts to the UI.""" + # TODO: We may finally have come up with a better naming convention. For ease of migration, + # we are going to keep deadline_alert here to match the model's name, but in the near future Review Comment: I do not understand why starting with `deadline_alert` and then renaming it to `deadline_definition`. Why not going with `deadline_definition`? You are writing the models in this PR, since it is a new table, so I do not get the "to match the model's name". ########## airflow-core/src/airflow/migrations/versions/0092_3_2_0_ui_improvements_for_deadlines.py: ########## @@ -0,0 +1,113 @@ +# +# 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 required fields to enable UI integrations for the Deadline Alerts feature. + +Revision ID: 55297ae24532 +Revises: b87d2135fa50 +Create Date: 2025-10-17 16:04:55.016272 +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op +from sqlalchemy_utils import UUIDType + +from airflow.migrations.db_types import TIMESTAMP + +revision = "55297ae24532" +down_revision = "b87d2135fa50" +branch_labels = None +depends_on = None +airflow_version = "3.2.0" + + +def upgrade(): + """Make changes to enable adding DeadlineAlerts to the UI.""" + # TODO: We may finally have come up with a better naming convention. For ease of migration, + # we are going to keep deadline_alert here to match the model's name, but in the near future + # when this migration work is done we should deprecate the name DeadlineAlert (and all related + # classes, tables, etc) and replace it with DeadlineDefinition. Then we will have the + # user-provided DeadlineDefinition, and the actual instance of a Definition is (still) the Deadline. + # This feels more intuitive than DeadlineAlert defining the Deadline. + + op.create_table( + "deadline_alert", + sa.Column("id", UUIDType(binary=False)), + sa.Column("created_at", TIMESTAMP(timezone=True), nullable=False, server_default=sa.func.now()), + sa.Column("name", sa.String(250), nullable=True), + sa.Column("description", sa.Text(), nullable=True), + sa.Column("reference", sa.JSON(), nullable=True), + sa.Column("interval", sa.Integer(), nullable=False), + sa.Column("callback", sa.JSON(), nullable=True), + sa.PrimaryKeyConstraint("id", name=op.f("deadline_alert_pkey")), + ) + + with op.batch_alter_table("deadline", schema=None) as batch_op: + batch_op.add_column(sa.Column("deadline_alert_id", UUIDType(binary=False), nullable=True)) + batch_op.add_column( + sa.Column("created_at", TIMESTAMP(timezone=True), nullable=False, server_default=sa.func.now()) + ) + batch_op.add_column( + sa.Column( + "last_updated_at", TIMESTAMP(timezone=True), nullable=False, server_default=sa.func.now() + ) + ) + + op.create_foreign_key( + op.f("deadline_deadline_alert_id_fkey"), + "deadline", + "deadline_alert", + ["deadline_alert_id"], + ["id"], + ondelete="SET NULL", + ) + + migrate_existing_deadline_alert_data_from_serialized_dag() + + +def migrate_existing_deadline_alert_data_from_serialized_dag(): + """Extract DeadlineAlert data from serialized DAG data and populate deadline_alert table.""" + # TODO: Implement a batch-based migration to account for memory constraints Review Comment: Do you intend to update this migration after it has been merged? It can disrupt developers. It is "better" to add new migrations and not modify existing ones in my opinion ########## airflow-core/src/airflow/models/deadline_alert.py: ########## @@ -0,0 +1,61 @@ +# 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 datetime import datetime + +import uuid6 +from sqlalchemy import JSON, Integer, String, Text +from sqlalchemy.orm import Mapped +from sqlalchemy_utils import UUIDType + +from airflow._shared.timezones import timezone +from airflow.models import Base +from airflow.utils.sqlalchemy import UtcDateTime, mapped_column + + +class DeadlineAlert(Base): + """Table containing DeadlineAlert properties.""" + + __tablename__ = "deadline_alert" + + id: Mapped[str] = mapped_column(UUIDType(binary=False), primary_key=True, default=uuid6.uuid7) + created_at: Mapped[datetime] = mapped_column(UtcDateTime, nullable=False, default=timezone.utcnow) + + name: Mapped[str | None] = mapped_column(String(250), nullable=True) + description: Mapped[str | None] = mapped_column(Text, nullable=True) + reference: Mapped[dict] = mapped_column(JSON, nullable=True) + interval: Mapped[int] = mapped_column(Integer, nullable=False) + callback: Mapped[dict] = mapped_column(JSON, nullable=True) Review Comment: Same ########## airflow-core/src/airflow/models/deadline_alert.py: ########## @@ -0,0 +1,61 @@ +# 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 datetime import datetime + +import uuid6 +from sqlalchemy import JSON, Integer, String, Text +from sqlalchemy.orm import Mapped +from sqlalchemy_utils import UUIDType + +from airflow._shared.timezones import timezone +from airflow.models import Base +from airflow.utils.sqlalchemy import UtcDateTime, mapped_column + + +class DeadlineAlert(Base): + """Table containing DeadlineAlert properties.""" + + __tablename__ = "deadline_alert" + + id: Mapped[str] = mapped_column(UUIDType(binary=False), primary_key=True, default=uuid6.uuid7) + created_at: Mapped[datetime] = mapped_column(UtcDateTime, nullable=False, default=timezone.utcnow) + + name: Mapped[str | None] = mapped_column(String(250), nullable=True) + description: Mapped[str | None] = mapped_column(Text, nullable=True) + reference: Mapped[dict] = mapped_column(JSON, nullable=True) Review Comment: Type is inconsistent. It this is nullable, then it should be `Mapped[dict | None]` -- 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]
