fix(link-module): Migration planner not closing connection correctly (#8881)

RESOLVES CC-405

**What**
Fixing mikro orm connection not closed during sync-links
This commit is contained in:
Adrien de Peretti
2024-08-29 15:10:13 +00:00
committed by GitHub
parent b6521e4c1a
commit bd20d66968
@@ -239,6 +239,7 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
const tableName = entity.meta.collection const tableName = entity.meta.collection
const orm = await this.createORM([entity]) const orm = await this.createORM([entity])
try {
const generator = orm.getSchemaGenerator() const generator = orm.getSchemaGenerator()
const platform = orm.em.getPlatform() const platform = orm.em.getPlatform()
const connection = orm.em.getConnection() const connection = orm.em.getConnection()
@@ -296,7 +297,6 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
return updateSQL.match(new RegExp(`${fragment}`, "ig")) return updateSQL.match(new RegExp(`${fragment}`, "ig"))
}) })
try {
return { return {
action: usesUnsafeCommands ? "notify" : "update", action: usesUnsafeCommands ? "notify" : "update",
linkDescriptor, linkDescriptor,
@@ -317,6 +317,8 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
*/ */
async createPlan() { async createPlan() {
const orm = await this.createORM() const orm = await this.createORM()
try {
await this.ensureMigrationsTable(orm) await this.ensureMigrationsTable(orm)
const executionActions: LinkMigrationsPlannerAction[] = [] const executionActions: LinkMigrationsPlannerAction[] = []
@@ -324,7 +326,9 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
await this.ensureMigrationsTableUpToDate(orm) await this.ensureMigrationsTableUpToDate(orm)
const trackedTables = await this.getTrackedLinksTables(orm) const trackedTables = await this.getTrackedLinksTables(orm)
const trackedTablesNames = trackedTables.map(({ table_name }) => table_name) const trackedTablesNames = trackedTables.map(
({ table_name }) => table_name
)
/** /**
* Looping through the new set of entities and generating * Looping through the new set of entities and generating
@@ -347,7 +351,10 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
/** /**
* Finding the tables to be removed * Finding the tables to be removed
*/ */
const tablesToRemove = arrayDifference(trackedTablesNames, linksTableNames) const tablesToRemove = arrayDifference(
trackedTablesNames,
linksTableNames
)
tablesToRemove.forEach((tableToRemove) => { tablesToRemove.forEach((tableToRemove) => {
executionActions.push({ executionActions.push({
action: "delete", action: "delete",
@@ -358,7 +365,6 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
}) })
}) })
try {
return executionActions return executionActions
} finally { } finally {
await orm.close(true) await orm.close(true)