kaxil commented on code in PR #49015:
URL: https://github.com/apache/airflow/pull/49015#discussion_r2039616040
##########
airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py:
##########
@@ -203,12 +206,26 @@ 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
+ """
+ )
+ )
+ if result.rowcount == 0:
+ break
Review Comment:
```suggestion
row_count = result.rowcount
if row_count == 0:
break
print(f"Migrated {row_count} task_instance rows in this
batch...")
```
--
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]