Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@


def upgrade() -> None:
op.execute(
"CREATE INDEX IF NOT EXISTS ix_tasks_metadata_gin "
"ON tasks USING GIN (task_metadata jsonb_path_ops)"
)
with op.get_context().autocommit_block():
op.execute(
"CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_metadata_gin "
"ON tasks USING GIN (task_metadata jsonb_path_ops)"
)


def downgrade() -> None:
Comment on lines 19 to 27
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 PostgreSQL forbids CREATE INDEX CONCURRENTLY (and DROP INDEX CONCURRENTLY) inside a transaction block. env.py sets transaction_per_migration=True, which wraps every migration in its own BEGIN/COMMIT, so calling op.execute("CREATE INDEX CONCURRENTLY …") directly will immediately raise ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block and abort the migration. The newer sibling migration a9959ebcbe98 (which also has down_revision = 'e9c4ff9e6542') correctly wraps its CONCURRENTLY statements in with op.get_context().autocommit_block(): — the same pattern documented in env.py's own inline comment. Both upgrade() and downgrade() need the same fix here.

Suggested change
def upgrade() -> None:
op.execute(
"CREATE INDEX IF NOT EXISTS ix_tasks_metadata_gin "
"ON tasks USING GIN (task_metadata jsonb_path_ops)"
)
with op.get_context().autocommit_block():
op.execute(
"CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_metadata_gin "
"ON tasks USING GIN (task_metadata jsonb_path_ops)"
)
def downgrade() -> None:
def upgrade() -> None:
with op.get_context().autocommit_block():
op.execute(
"CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_metadata_gin "
"ON tasks USING GIN (task_metadata jsonb_path_ops)"
)
def downgrade() -> None:
with op.get_context().autocommit_block():
op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_tasks_metadata_gin")
Prompt To Fix With AI
This is a comment left during a code review.
Path: agentex/database/migrations/alembic/versions/2026_05_04_1111_add_tasks_metadata_gin_index_e9c4ff9e6542.py
Line: 19-27

Comment:
PostgreSQL forbids `CREATE INDEX CONCURRENTLY` (and `DROP INDEX CONCURRENTLY`) inside a transaction block. `env.py` sets `transaction_per_migration=True`, which wraps every migration in its own `BEGIN`/`COMMIT`, so calling `op.execute("CREATE INDEX CONCURRENTLY …")` directly will immediately raise `ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block` and abort the migration. The newer sibling migration `a9959ebcbe98` (which also has `down_revision = 'e9c4ff9e6542'`) correctly wraps its CONCURRENTLY statements in `with op.get_context().autocommit_block():` — the same pattern documented in `env.py`'s own inline comment. Both `upgrade()` and `downgrade()` need the same fix here.

```suggestion
def upgrade() -> None:
    with op.get_context().autocommit_block():
        op.execute(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_tasks_metadata_gin "
            "ON tasks USING GIN (task_metadata jsonb_path_ops)"
        )

def downgrade() -> None:
    with op.get_context().autocommit_block():
        op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_tasks_metadata_gin")
```

How can I resolve this? If you propose a fix, please make it concise.

Fix in Cursor Fix in Claude Code Fix in Codex

op.execute("DROP INDEX IF EXISTS ix_tasks_metadata_gin")
with op.get_context().autocommit_block():
op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_tasks_metadata_gin")
Loading