Typeorm: Migrations should each run in a separate transaction

Created on 5 Jan 2018  路  1Comment  路  Source: typeorm/typeorm

It seems that all migrations run in a single transaction (https://github.com/typeorm/typeorm/blob/master/src/migration/MigrationExecutor.ts). This can cause issues, for example:

  1. Add a migration that creates a table.
  2. Add a migration that runs CREATE INDEX CONCURRENTLY (PostgreSQL), to add an index to that table outside of the current transaction, using the workaround described in https://github.com/typeorm/typeorm/issues/1169.
  3. Connect to and run migrations on an empty database

Expected result: Migrations succeed.
Actual result: Fails because the transaction that creates the table in the first migration _is still open and uncommitted_ when the second migration runs.

Unless there is a reason to use a single transaction for all migrations, I suggest using a separate transaction per migration, which should fix this issue.

migrations

Most helpful comment

Fixed in the latest @next.
Now you can specify an option to the migration:run command and disable transaction:

migration:run -t=false

You can try it via npm i typeorm@next.

>All comments

Fixed in the latest @next.
Now you can specify an option to the migration:run command and disable transaction:

migration:run -t=false

You can try it via npm i typeorm@next.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shroudedcode picture shroudedcode  路  3Comments

NoNameProvided picture NoNameProvided  路  3Comments

SPAHI4 picture SPAHI4  路  3Comments

arthurvasconcelos picture arthurvasconcelos  路  3Comments

guscastro picture guscastro  路  3Comments