fix: delete syntax

This commit is contained in:
Rajat Ahuja 2026-01-14 14:43:09 -05:00
parent f8641f01c8
commit 670ab6b7d5
1 changed files with 12 additions and 5 deletions

View File

@ -231,16 +231,18 @@ def downgrade() -> None:
batch_size = 5000
# Delete active_queue_sessions for queue items with NULL workspace_name
# Use CTE-based delete since PostgreSQL doesn't support DELETE ... LIMIT
while True:
result = conn.execute(
sa.text(
f"""
DELETE FROM "{schema}".active_queue_sessions
WHERE work_unit_key IN (
WITH del AS (
SELECT work_unit_key FROM "{schema}".queue
WHERE workspace_name IS NULL
LIMIT :batch_size
)
LIMIT :batch_size
DELETE FROM "{schema}".active_queue_sessions
WHERE work_unit_key IN (SELECT work_unit_key FROM del)
"""
),
{"batch_size": batch_size},
@ -249,13 +251,18 @@ def downgrade() -> None:
break
# Delete queue items with NULL workspace_name
# Use CTE with ctid for safe batched delete in PostgreSQL
while True:
result = conn.execute(
sa.text(
f"""
WITH del AS (
SELECT ctid FROM "{schema}".queue
WHERE workspace_name IS NULL
LIMIT :batch_size
)
DELETE FROM "{schema}".queue
WHERE workspace_name IS NULL
LIMIT :batch_size
WHERE ctid IN (SELECT ctid FROM del)
"""
),
{"batch_size": batch_size},