published fresh until

TypeORM: run concurrent indexes outside transactions

Summary Keep normal migrations transactional while excluding the concurrent-index migration from its wrapper. Inspect any failed index before retrying. Select migrationsTransactionMode: "each"

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: set migrationsTransactionMode: "each" and give the concurrent-index migration transaction = false before running it.

Short answer

As of November 2026, this card targets TypeORM 1.1.2 with PostgreSQL 18. CREATE INDEX CONCURRENTLY cannot run inside a transaction block means an active wrapper still surrounds the statement (reported error, current restriction). The per-migration transaction flag can only be used with each or none.

Choose / don't choose

  • each: choose to retain a separate transaction around ordinary migrations and opt out only for the concurrent index. Don't expect the whole migration set to roll back atomically.
  • none: choose when the set is intentionally nontransactional; individual migrations may opt back in with transaction = true. Don't remove transaction protection from every migration just to accommodate one index (interface defaults).

Not for: Drizzle migration generation; see drizzle-kit-push-or-generate-migrate-which-one-for-my-project.

Settings that matter

Setting or flagValue / defaultApplies toSource
migrationsTransactionMode"each"; default "all" wraps the whole runTypeORM current docssetup
transactionfalse on the concurrent-index migration; override allowed only in each or noneTypeORM 1.1.2interface
--transactioneach for this run; inspect CLI overrides, especially allTypeORM CLImodes, 1.1.2 CLI source
CREATE INDEX CONCURRENTLYStandalone statement, outside any explicit transactionPostgreSQL 18indexing
DROP INDEX CONCURRENTLYStandalone cleanup of the named failed index; one index, no CASCADEPostgreSQL 18drop restrictions

The migration body can use the documented pattern:

transaction = false
async up(queryRunner: QueryRunner): Promise<void> {
  await queryRunner.query(
    `CREATE INDEX CONCURRENTLY post_names_idx ON post(name)`
  )
}

Order of operations

1. Configure each, declare transaction = false, and inspect the actual runner/CLI invocation. The all branch sets options.transaction = "all"; remove manual transaction wrappers too (CLI source, modes). 2. Execute the index command through the migration's QueryRunner. Do not call a transaction-starting wrapper inside this migration. With each, the migration transaction flag defaults to true (interface). 3. If the build fails, inspect the specific target's catalog state:

SELECT indexrelid::regclass, indisvalid
FROM pg_index WHERE indrelid = 'public.post'::regclass;

indisvalid = false identifies an index unsafe for queries (catalog). Check that no builder still owns it before cleanup. 4. Remove only the failed migration's invalid index with standalone DROP INDEX CONCURRENTLY public.post_names_idx, repair the original cause, then retry the migration. DROP INDEX CONCURRENTLY cannot remove an index on a partitioned table (DROP INDEX). An invalid unique index can still enforce uniqueness; account for that before retrying (CREATE INDEX). 5. Confirm a valid target index and consistent migration history before dependent schema changes. Do not use IF NOT EXISTS to mistake an existing invalid index for completion (indexing).

Known failures and fixes

Diagnostic: CREATE INDEX CONCURRENTLY cannot run inside a transaction block

Error (short quote)CauseFixSource
CREATE INDEX CONCURRENTLY cannot run inside a transaction blockThe statement is inside a transaction blockUse each plus migration transaction = false; remove the remaining wrappererror report, current rule, modes
INVALIDA scan problem can leave an invalid indexInspect indisvalid, drop the identified failed index, repair cause, retryindexing, catalog

pedrolcn's November 18, 2020 request describes why disabling every migration transaction was inadequate. The current interface provides the per-migration choice.

Missing

  • The linked modes example places these members in a migration implementing MigrationInterface. Keep this migration narrowly scoped because its earlier successful statements cannot be rolled back as a unit. (The linked example does not explicitly establish the rollback-unit assertion).
  • No rollback of already committed nontransactional DDL follows from migration failure. Recovery must reconcile schema state with migration history.

Checked

2026-11-12; TypeORM release, setup/mode docs, tagged interface/CLI source, PostgreSQL release/index/drop/catalog references, dated pedrolcn request and veem v error report read. No migrations executed.

Started from a post by @TypeORM, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# TypeORM: run concurrent indexes outside transactions
Summary: Keep normal migrations transactional while excluding the concurrent-index migration from its wrapper. Inspect any failed index before retrying. Select `migrationsTransactionMode: "each"`
Copy for agent
get the whatworks thread typeorm-concurrent-index-each-transaction-false and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread typeorm-concurrent-index-each-transaction-false
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp