This is an automated email from the ASF dual-hosted git repository.

kalyanr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new b175e3c81fb rename deadline column to "deadline_time" in Deadline 
Table (#51026)
b175e3c81fb is described below

commit b175e3c81fb473fd364f86a612df228d94f25c5d
Author: Kalyan R <[email protected]>
AuthorDate: Thu Jun 12 22:23:05 2025 +0530

    rename deadline column to "deadline_time" in Deadline Table (#51026)
    
    * rename deadline column to time in Deadline Table
    
    * rename migration file name and update index
    
    * fix downgrade
    
    * fix upgrade
    
    * fix upgrade
    
    * fix upgrade
    
    * recreate index after column is renamed
    
    * fix recency column name
    
    * fix upgrade
    
    * change deadline.time to deadline.deadline_at
    
    * fix upgrade
    
    * rename deadline to deadline_time
---
 airflow-core/docs/img/airflow_erd.sha256           |  2 +-
 airflow-core/docs/img/airflow_erd.svg              | 58 +++++++++++-----------
 airflow-core/docs/migrations-ref.rst               |  5 +-
 ...0_rename_and_change_type_of_deadline_column.py} | 14 ++++--
 airflow-core/src/airflow/models/deadline.py        | 10 ++--
 airflow-core/src/airflow/utils/db_cleanup.py       |  2 +-
 airflow-core/tests/unit/models/test_deadline.py    | 16 +++---
 7 files changed, 57 insertions(+), 50 deletions(-)

diff --git a/airflow-core/docs/img/airflow_erd.sha256 
b/airflow-core/docs/img/airflow_erd.sha256
index 86f013f2090..ccd0a7679a3 100644
--- a/airflow-core/docs/img/airflow_erd.sha256
+++ b/airflow-core/docs/img/airflow_erd.sha256
@@ -1 +1 @@
-2732a5f7846dd279440b101904898d683a22c27fdecccba1c99ff9cbbc0e59e3
\ No newline at end of file
+789370f7c29cc290c307562a13f06576d8651e12916cc42f89653f8127c00210
\ No newline at end of file
diff --git a/airflow-core/docs/img/airflow_erd.svg 
b/airflow-core/docs/img/airflow_erd.svg
index 46cdc48fbbe..648a437fa97 100644
--- a/airflow-core/docs/img/airflow_erd.svg
+++ b/airflow-core/docs/img/airflow_erd.svg
@@ -1702,35 +1702,35 @@
 <!-- deadline -->
 <g id="node31" class="node">
 <title>deadline</title>
-<polygon fill="none" stroke="black" points="1785,-2192.5 1785,-2220.5 
2054,-2220.5 2054,-2192.5 1785,-2192.5"/>
-<text text-anchor="start" x="1881.5" y="-2203.7" 
font-family="Helvetica,sans-Serif" font-weight="bold" 
font-size="16.00">deadline</text>
-<polygon fill="none" stroke="black" points="1785,-2167.5 1785,-2192.5 
2054,-2192.5 2054,-2167.5 1785,-2167.5"/>
-<text text-anchor="start" x="1790" y="-2177.3" 
font-family="Helvetica,sans-Serif" text-decoration="underline" 
font-size="14.00">id</text>
-<text text-anchor="start" x="1803" y="-2177.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
-<text text-anchor="start" x="1808" y="-2177.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [UUID]</text>
-<text text-anchor="start" x="1860" y="-2177.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> NOT NULL</text>
-<polygon fill="none" stroke="black" points="1785,-2142.5 1785,-2167.5 
2054,-2167.5 2054,-2142.5 1785,-2142.5"/>
-<text text-anchor="start" x="1790" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">callback</text>
-<text text-anchor="start" x="1847" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
-<text text-anchor="start" x="1852" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [VARCHAR(500)]</text>
-<text text-anchor="start" x="1973" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> NOT NULL</text>
-<polygon fill="none" stroke="black" points="1785,-2117.5 1785,-2142.5 
2054,-2142.5 2054,-2117.5 1785,-2117.5"/>
-<text text-anchor="start" x="1790" y="-2127.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">callback_kwargs</text>
-<text text-anchor="start" x="1903" y="-2127.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
-<text text-anchor="start" x="1908" y="-2127.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [JSON]</text>
-<polygon fill="none" stroke="black" points="1785,-2092.5 1785,-2117.5 
2054,-2117.5 2054,-2092.5 1785,-2092.5"/>
-<text text-anchor="start" x="1790" y="-2102.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">dag_id</text>
-<text text-anchor="start" x="1836" y="-2102.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
-<text text-anchor="start" x="1841" y="-2102.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [VARCHAR(250)]</text>
-<polygon fill="none" stroke="black" points="1785,-2067.5 1785,-2092.5 
2054,-2092.5 2054,-2067.5 1785,-2067.5"/>
-<text text-anchor="start" x="1790" y="-2077.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">dagrun_id</text>
-<text text-anchor="start" x="1860" y="-2077.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
-<text text-anchor="start" x="1865" y="-2077.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [INTEGER]</text>
-<polygon fill="none" stroke="black" points="1785,-2042.5 1785,-2067.5 
2054,-2067.5 2054,-2042.5 1785,-2042.5"/>
-<text text-anchor="start" x="1790" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">deadline</text>
-<text text-anchor="start" x="1850" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
-<text text-anchor="start" x="1855" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [TIMESTAMP]</text>
-<text text-anchor="start" x="1951" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> NOT NULL</text>
+<polygon fill="none" stroke="black" points="1777,-2192.5 1777,-2220.5 
2061,-2220.5 2061,-2192.5 1777,-2192.5"/>
+<text text-anchor="start" x="1881" y="-2203.7" 
font-family="Helvetica,sans-Serif" font-weight="bold" 
font-size="16.00">deadline</text>
+<polygon fill="none" stroke="black" points="1777,-2167.5 1777,-2192.5 
2061,-2192.5 2061,-2167.5 1777,-2167.5"/>
+<text text-anchor="start" x="1782" y="-2177.3" 
font-family="Helvetica,sans-Serif" text-decoration="underline" 
font-size="14.00">id</text>
+<text text-anchor="start" x="1795" y="-2177.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
+<text text-anchor="start" x="1800" y="-2177.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [UUID]</text>
+<text text-anchor="start" x="1852" y="-2177.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> NOT NULL</text>
+<polygon fill="none" stroke="black" points="1777,-2142.5 1777,-2167.5 
2061,-2167.5 2061,-2142.5 1777,-2142.5"/>
+<text text-anchor="start" x="1782" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">callback</text>
+<text text-anchor="start" x="1839" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
+<text text-anchor="start" x="1844" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [VARCHAR(500)]</text>
+<text text-anchor="start" x="1965" y="-2152.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> NOT NULL</text>
+<polygon fill="none" stroke="black" points="1777,-2117.5 1777,-2142.5 
2061,-2142.5 2061,-2117.5 1777,-2117.5"/>
+<text text-anchor="start" x="1782" y="-2127.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">callback_kwargs</text>
+<text text-anchor="start" x="1895" y="-2127.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
+<text text-anchor="start" x="1900" y="-2127.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [JSON]</text>
+<polygon fill="none" stroke="black" points="1777,-2092.5 1777,-2117.5 
2061,-2117.5 2061,-2092.5 1777,-2092.5"/>
+<text text-anchor="start" x="1782" y="-2102.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">dag_id</text>
+<text text-anchor="start" x="1828" y="-2102.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
+<text text-anchor="start" x="1833" y="-2102.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [VARCHAR(250)]</text>
+<polygon fill="none" stroke="black" points="1777,-2067.5 1777,-2092.5 
2061,-2092.5 2061,-2067.5 1777,-2067.5"/>
+<text text-anchor="start" x="1782" y="-2077.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">dagrun_id</text>
+<text text-anchor="start" x="1852" y="-2077.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
+<text text-anchor="start" x="1857" y="-2077.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [INTEGER]</text>
+<polygon fill="none" stroke="black" points="1777,-2042.5 1777,-2067.5 
2061,-2067.5 2061,-2042.5 1777,-2042.5"/>
+<text text-anchor="start" x="1782" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00">deadline_time</text>
+<text text-anchor="start" x="1879" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> </text>
+<text text-anchor="start" x="1884" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> [TIMESTAMP]</text>
+<text text-anchor="start" x="1980" y="-2052.3" 
font-family="Helvetica,sans-Serif" font-size="14.00"> NOT NULL</text>
 </g>
 <!-- dag&#45;&#45;deadline -->
 <g id="edge26" class="edge">
diff --git a/airflow-core/docs/migrations-ref.rst 
b/airflow-core/docs/migrations-ref.rst
index f4462ab7273..0c1b0b4a8e4 100644
--- a/airflow-core/docs/migrations-ref.rst
+++ b/airflow-core/docs/migrations-ref.rst
@@ -43,8 +43,9 @@ Here's the list of all the Database Migrations that are 
executed via when you ru
 |                         |                  |                   | 
task_instance.dag_version_id foreign key constraint to       |
 |                         |                  |                   | RESTRICT.   
                                                 |
 
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
-| ``0242ac120002``        | ``dfee8bd5d574`` | ``3.1.0``         | Change the 
Deadline column in the Deadline table from        |
-|                         |                  |                   | DateTime to 
UTC DateTime.                                    |
+| ``0242ac120002``        | ``dfee8bd5d574`` | ``3.1.0``         | Rename 
Deadline column in the Deadline table from deadline   |
+|                         |                  |                   | to 
deadline_time and change its type from DateTime to UTC    |
+|                         |                  |                   | DateTime.   
                                                 |
 
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
 | ``dfee8bd5d574``        | ``fe199e1abd77`` | ``3.1.0``         | Add 
Deadline to Dag.                                         |
 
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
diff --git 
a/airflow-core/src/airflow/migrations/versions/0071_3_1_0_change_deadline_to_utc.py
 
b/airflow-core/src/airflow/migrations/versions/0071_3_1_0_rename_and_change_type_of_deadline_column.py
similarity index 72%
rename from 
airflow-core/src/airflow/migrations/versions/0071_3_1_0_change_deadline_to_utc.py
rename to 
airflow-core/src/airflow/migrations/versions/0071_3_1_0_rename_and_change_type_of_deadline_column.py
index b8cce104d29..b7fd7933a29 100644
--- 
a/airflow-core/src/airflow/migrations/versions/0071_3_1_0_change_deadline_to_utc.py
+++ 
b/airflow-core/src/airflow/migrations/versions/0071_3_1_0_rename_and_change_type_of_deadline_column.py
@@ -17,7 +17,7 @@
 # under the License.
 
 """
-Change the Deadline column in the Deadline table from DateTime to UTC DateTime.
+Rename Deadline column in the Deadline table from deadline to deadline_time 
and change its type from DateTime to UTC DateTime.
 
 Revision ID: 0242ac120002
 Revises: dfee8bd5d574
@@ -39,22 +39,28 @@ airflow_version = "3.1.0"
 
 
 def upgrade():
-    """Apply change deadline column in the deadline table to UTC datetime."""
+    """Apply change to deadline column in the deadline table."""
     with op.batch_alter_table("deadline", schema=None) as batch_op:
+        batch_op.drop_index("deadline_idx")
         batch_op.alter_column(
             "deadline",
             existing_type=sa.DateTime(),
             type_=TIMESTAMP(timezone=True),
             existing_nullable=False,
+            new_column_name="deadline_time",
         )
+    op.create_index("deadline_time_idx", "deadline", ["deadline_time"], 
unique=False)
 
 
 def downgrade():
-    """Unapply change deadline column in the deadline table to UTC datetime."""
+    """Unapply change to deadline column in the deadline table."""
     with op.batch_alter_table("deadline", schema=None) as batch_op:
+        batch_op.drop_index("deadline_time_idx")
         batch_op.alter_column(
-            "deadline",
+            "deadline_time",
             existing_type=TIMESTAMP(timezone=True),
             type_=sa.DateTime(),
             existing_nullable=False,
+            new_column_name="deadline",
         )
+    op.create_index("deadline_idx", "deadline", ["deadline"], unique=False)
diff --git a/airflow-core/src/airflow/models/deadline.py 
b/airflow-core/src/airflow/models/deadline.py
index 2e58a8731ec..9891d3947ee 100644
--- a/airflow-core/src/airflow/models/deadline.py
+++ b/airflow-core/src/airflow/models/deadline.py
@@ -56,7 +56,7 @@ class Deadline(Base):
     dagrun_id = Column(Integer, ForeignKey("dag_run.id", ondelete="CASCADE"))
 
     # The time after which the Deadline has passed and the callback should be 
triggered.
-    deadline = Column(UtcDateTime, nullable=False)
+    deadline_time = Column(UtcDateTime, nullable=False)
     # The Callback to be called when the Deadline has passed.
     callback = Column(String(500), nullable=False)
     # Serialized kwargs to pass to the callback.
@@ -64,18 +64,18 @@ class Deadline(Base):
 
     dagrun = relationship("DagRun", back_populates="deadlines")
 
-    __table_args__ = (Index("deadline_idx", deadline, unique=False),)
+    __table_args__ = (Index("deadline_time_idx", deadline_time, unique=False),)
 
     def __init__(
         self,
-        deadline: datetime,
+        deadline_time: datetime,
         callback: str,
         callback_kwargs: dict | None = None,
         dag_id: str | None = None,
         dagrun_id: int | None = None,
     ):
         super().__init__()
-        self.deadline = deadline
+        self.deadline_time = deadline_time
         self.callback = callback
         self.callback_kwargs = callback_kwargs
         self.dag_id = dag_id
@@ -95,7 +95,7 @@ class Deadline(Base):
 
         return (
             f"[{resource_type} Deadline] {resource_details} needed by "
-            f"{self.deadline} or run: {self.callback}({callback_kwargs})"
+            f"{self.deadline_time} or run: {self.callback}({callback_kwargs})"
         )
 
     @classmethod
diff --git a/airflow-core/src/airflow/utils/db_cleanup.py 
b/airflow-core/src/airflow/utils/db_cleanup.py
index 4c8e0a0dbc7..02b03075232 100644
--- a/airflow-core/src/airflow/utils/db_cleanup.py
+++ b/airflow-core/src/airflow/utils/db_cleanup.py
@@ -127,7 +127,7 @@ config_list: list[_TableConfig] = [
     _TableConfig(table_name="celery_tasksetmeta", 
recency_column_name="date_done"),
     _TableConfig(table_name="trigger", recency_column_name="created_date"),
     _TableConfig(table_name="dag_version", recency_column_name="created_at"),
-    _TableConfig(table_name="deadline", recency_column_name="deadline"),
+    _TableConfig(table_name="deadline", recency_column_name="deadline_time"),
 ]
 
 # We need to have `fallback="database"` because this is executed at top level 
code and provider configuration
diff --git a/airflow-core/tests/unit/models/test_deadline.py 
b/airflow-core/tests/unit/models/test_deadline.py
index a3ce6f8c3ae..599556587fd 100644
--- a/airflow-core/tests/unit/models/test_deadline.py
+++ b/airflow-core/tests/unit/models/test_deadline.py
@@ -84,7 +84,7 @@ class TestDeadline:
     def test_add_deadline(self, dagrun, session):
         assert session.query(Deadline).count() == 0
         deadline_orm = Deadline(
-            deadline=DEFAULT_DATE,
+            deadline_time=DEFAULT_DATE,
             callback=TEST_CALLBACK_PATH,
             callback_kwargs=TEST_CALLBACK_KWARGS,
             dag_id=DAG_ID,
@@ -98,20 +98,20 @@ class TestDeadline:
         result = session.scalars(select(Deadline)).first()
         assert result.dag_id == deadline_orm.dag_id
         assert result.dagrun_id == deadline_orm.dagrun_id
-        assert result.deadline == deadline_orm.deadline
+        assert result.deadline_time == deadline_orm.deadline_time
         assert result.callback == deadline_orm.callback
         assert result.callback_kwargs == deadline_orm.callback_kwargs
 
     def test_orm(self):
         deadline_orm = Deadline(
-            deadline=DEFAULT_DATE,
+            deadline_time=DEFAULT_DATE,
             callback=TEST_CALLBACK_PATH,
             callback_kwargs=TEST_CALLBACK_KWARGS,
             dag_id=DAG_ID,
             dagrun_id=RUN_ID,
         )
 
-        assert deadline_orm.deadline == DEFAULT_DATE
+        assert deadline_orm.deadline_time == DEFAULT_DATE
         assert deadline_orm.callback == TEST_CALLBACK_PATH
         assert deadline_orm.callback_kwargs == TEST_CALLBACK_KWARGS
         assert deadline_orm.dag_id == DAG_ID
@@ -119,7 +119,7 @@ class TestDeadline:
 
     def test_repr_with_callback_kwargs(self):
         deadline_orm = Deadline(
-            deadline=DEFAULT_DATE,
+            deadline_time=DEFAULT_DATE,
             callback=TEST_CALLBACK_PATH,
             callback_kwargs=TEST_CALLBACK_KWARGS,
             dag_id=DAG_ID,
@@ -129,12 +129,12 @@ class TestDeadline:
         assert (
             repr(deadline_orm)
             == f"[DagRun Deadline] Dag: {deadline_orm.dag_id} Run: 
{deadline_orm.dagrun_id} needed by "
-            f"{deadline_orm.deadline} or run: 
{TEST_CALLBACK_PATH}({json.dumps(deadline_orm.callback_kwargs)})"
+            f"{deadline_orm.deadline_time} or run: 
{TEST_CALLBACK_PATH}({json.dumps(deadline_orm.callback_kwargs)})"
         )
 
     def test_repr_without_callback_kwargs(self):
         deadline_orm = Deadline(
-            deadline=DEFAULT_DATE,
+            deadline_time=DEFAULT_DATE,
             callback=TEST_CALLBACK_PATH,
             dag_id=DAG_ID,
             dagrun_id=RUN_ID,
@@ -144,7 +144,7 @@ class TestDeadline:
         assert (
             repr(deadline_orm)
             == f"[DagRun Deadline] Dag: {deadline_orm.dag_id} Run: 
{deadline_orm.dagrun_id} needed by "
-            f"{deadline_orm.deadline} or run: {TEST_CALLBACK_PATH}()"
+            f"{deadline_orm.deadline_time} or run: {TEST_CALLBACK_PATH}()"
         )
 
 

Reply via email to