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:
1 parent
b6521e4c1a
commit
bd20d66968
1 file changed
+10
-4
@@ -239,6 +239,7 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
|
||||
const tableName = entity.meta.collection
|
||||
const orm = await this.createORM([entity])
|
||||
|
||||
try {
|
||||
const generator = orm.getSchemaGenerator()
|
||||
const platform = orm.em.getPlatform()
|
||||
const connection = orm.em.getConnection()
|
||||
@@ -296,7 +297,6 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
|
||||
return updateSQL.match(new RegExp(`${fragment}`, "ig"))
|
||||
})
|
||||
|
||||
try {
|
||||
return {
|
||||
action: usesUnsafeCommands ? "notify" : "update",
|
||||
linkDescriptor,
|
||||
@@ -317,6 +317,8 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
|
||||
*/
|
||||
async createPlan() {
|
||||
const orm = await this.createORM()
|
||||
|
||||
try {
|
||||
await this.ensureMigrationsTable(orm)
|
||||
|
||||
const executionActions: LinkMigrationsPlannerAction[] = []
|
||||
@@ -324,7 +326,9 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
|
||||
await this.ensureMigrationsTableUpToDate(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
|
||||
@@ -347,7 +351,10 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
|
||||
/**
|
||||
* Finding the tables to be removed
|
||||
*/
|
||||
const tablesToRemove = arrayDifference(trackedTablesNames, linksTableNames)
|
||||
const tablesToRemove = arrayDifference(
|
||||
trackedTablesNames,
|
||||
linksTableNames
|
||||
)
|
||||
tablesToRemove.forEach((tableToRemove) => {
|
||||
executionActions.push({
|
||||
action: "delete",
|
||||
@@ -358,7 +365,6 @@ export class MigrationsExecutionPlanner implements ILinkMigrationsPlanner {
|
||||
})
|
||||
})
|
||||
|
||||
try {
|
||||
return executionActions
|
||||
} finally {
|
||||
await orm.close(true)
|
||||
|
||||
Reference in new issue
Block a user