Ensure proper cleanup of the database connection in `createSchema` (#5315)

* Ensure proper cleanup of the database connection in `createSchema` method in `MySQLRecordManager`.

* Update MySQLrecordManager.ts

* Refactor createSchema to optimize dataSource usage

Refactor createSchema method to avoid duplicate dataSource retrieval.

* Refactor createSchema method for efficiency

Refactor createSchema to avoid redundant dataSource retrieval.

---------

Co-authored-by: Henry Heng <henryheng@flowiseai.com>
This commit is contained in:
Marko 2025-10-28 13:29:45 +01:00 committed by GitHub
parent ac565b8981
commit 9554b1a8e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions

View File

@ -205,8 +205,8 @@ class MySQLRecordManager implements RecordManagerInterface {
} }
async createSchema(): Promise<void> { async createSchema(): Promise<void> {
const dataSource = await this.getDataSource()
try { try {
const dataSource = await this.getDataSource()
const queryRunner = dataSource.createQueryRunner() const queryRunner = dataSource.createQueryRunner()
const tableName = this.sanitizeTableName(this.tableName) const tableName = this.sanitizeTableName(this.tableName)
@ -241,6 +241,8 @@ class MySQLRecordManager implements RecordManagerInterface {
return return
} }
throw e throw e
} finally {
await dataSource.destroy()
} }
} }

View File

@ -222,8 +222,8 @@ class PostgresRecordManager implements RecordManagerInterface {
} }
async createSchema(): Promise<void> { async createSchema(): Promise<void> {
const dataSource = await this.getDataSource()
try { try {
const dataSource = await this.getDataSource()
const queryRunner = dataSource.createQueryRunner() const queryRunner = dataSource.createQueryRunner()
const tableName = this.sanitizeTableName(this.tableName) const tableName = this.sanitizeTableName(this.tableName)
@ -251,6 +251,8 @@ class PostgresRecordManager implements RecordManagerInterface {
return return
} }
throw e throw e
} finally {
await dataSource.destroy()
} }
} }

View File

@ -179,8 +179,8 @@ class SQLiteRecordManager implements RecordManagerInterface {
} }
async createSchema(): Promise<void> { async createSchema(): Promise<void> {
const dataSource = await this.getDataSource()
try { try {
const dataSource = await this.getDataSource()
const queryRunner = dataSource.createQueryRunner() const queryRunner = dataSource.createQueryRunner()
const tableName = this.sanitizeTableName(this.tableName) const tableName = this.sanitizeTableName(this.tableName)
@ -208,6 +208,8 @@ CREATE INDEX IF NOT EXISTS group_id_index ON "${tableName}" (group_id);`)
return return
} }
throw e throw e
} finally {
await dataSource.destroy()
} }
} }