Skip to content

Commit

Permalink
Run queries within queryRunner transaction sequentially (twentyhq#5668)
Browse files Browse the repository at this point in the history
Within a queryRunner transaction, it is important that migrations are
run subsequently and not concurrently: otherwise if an error is thrown
by one of the query, it will abort the transaction; any subsequent query
running on the same queryRunner will cause the error _current
transaction is aborted, commands ignored until end of transaction
block_.

Using an async function in a map as below does not guarantee that each
query terminates before iterating over the next one, which can be an
issue as described above, and which seems to cause [this
sentry](https://twenty-v7.sentry.io/issues/5258406553/?environment=prod&project=4507072499810304&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D&referrer=issue-stream&statsPeriod=7d&stream_index=4).
  • Loading branch information
ijreilly authored May 30, 2024
1 parent 9a23f9b commit 339aee6
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class WorkspaceMigrationEnumService {
`SELECT id, "${oldColumnName}" FROM "${schemaName}"."${tableName}"`,
);

values.map(async (value) => {
for (const value of values) {
let val = value[oldColumnName];

if (/^\{.*\}$/.test(val)) {
Expand All @@ -159,7 +159,7 @@ export class WorkspaceMigrationEnumService {
SET "${columnDefinition.columnName}" = ${val}
WHERE id='${value.id}'
`);
});
}
}

private async dropOldEnumType(
Expand Down

0 comments on commit 339aee6

Please sign in to comment.