Skip to content

Commit 021a6c7

Browse files
fix(schedules): guard name reuse rollback
Allow downgrade only when no duplicate schedule names exist across rows, and fail before changing indexes when manual cleanup is required. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f7cd313 commit 021a6c7

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

agentex/database/migrations/alembic/versions/2026_07_08_1626_schedule_identity_id_handles_9a4b8c7d6e5f.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from collections.abc import Sequence
1313

14+
import sqlalchemy as sa
1415
from alembic import op
1516

1617
# revision identifiers, used by Alembic.
@@ -34,6 +35,22 @@ def upgrade() -> None:
3435

3536

3637
def downgrade() -> None:
38+
connection = op.get_bind()
39+
duplicate = connection.execute(
40+
sa.text(
41+
"SELECT 1 FROM agent_run_schedules "
42+
"GROUP BY agent_id, name "
43+
"HAVING COUNT(*) > 1 "
44+
"LIMIT 1"
45+
)
46+
).scalar()
47+
if duplicate is not None:
48+
raise RuntimeError(
49+
"Downgrade is unsafe after schedule name reuse. Clean up duplicate "
50+
"(agent_id, name) rows before recreating "
51+
"uq_agent_run_schedules_agent_name."
52+
)
53+
3754
with op.get_context().autocommit_block():
3855
op.execute(
3956
"CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "

0 commit comments

Comments
 (0)