ephraimbuddy commented on code in PR #49015:
URL: https://github.com/apache/airflow/pull/49015#discussion_r2041881420
##########
airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py:
##########
@@ -203,12 +206,28 @@ def upgrade():
if dialect_name == "postgresql":
op.execute(pg_uuid7_fn)
- # TODO: Add batching to handle updates in smaller chunks for large
tables to avoid locking
# Migrate existing rows with UUID v7 using a timestamp-based generation
- op.execute(
- "UPDATE task_instance SET id =
uuid_generate_v7(coalesce(queued_dttm, start_date, clock_timestamp()))"
- )
-
+ while True:
+ result = conn.execute(
+ text(
+ f"""
+ WITH cte AS (
+ SELECT ctid
+ FROM task_instance
+ WHERE id IS NULL
+ LIMIT {batch_size}
+ )
+ UPDATE task_instance
+ SET id = uuid_generate_v7(coalesce(queued_dttm,
start_date, clock_timestamp()))
+ FROM cte
+ WHERE task_instance.ctid = cte.ctid
+ """
+ )
Review Comment:
```suggestion
).bindparams(batch_size=batch_size)
```
This will help in DB caching.
##########
airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py:
##########
@@ -203,12 +206,28 @@ def upgrade():
if dialect_name == "postgresql":
op.execute(pg_uuid7_fn)
- # TODO: Add batching to handle updates in smaller chunks for large
tables to avoid locking
# Migrate existing rows with UUID v7 using a timestamp-based generation
- op.execute(
- "UPDATE task_instance SET id =
uuid_generate_v7(coalesce(queued_dttm, start_date, clock_timestamp()))"
- )
-
+ while True:
+ result = conn.execute(
+ text(
+ f"""
Review Comment:
```suggestion
"""
```
##########
airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py:
##########
@@ -203,12 +206,28 @@ def upgrade():
if dialect_name == "postgresql":
op.execute(pg_uuid7_fn)
- # TODO: Add batching to handle updates in smaller chunks for large
tables to avoid locking
# Migrate existing rows with UUID v7 using a timestamp-based generation
- op.execute(
- "UPDATE task_instance SET id =
uuid_generate_v7(coalesce(queued_dttm, start_date, clock_timestamp()))"
- )
-
+ while True:
+ result = conn.execute(
+ text(
+ f"""
+ WITH cte AS (
+ SELECT ctid
+ FROM task_instance
+ WHERE id IS NULL
+ LIMIT {batch_size}
Review Comment:
```suggestion
LIMIT :batch_size
```
--
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]