Refactor `createSchema` method in record managers to streamline data source retrieval and ensure proper cleanup. Updated MySQL, Postgres, and SQLite implementations for consistency and resource management.

This commit is contained in:
Henry 2025-10-20 10:56:36 +01:00
parent 84441850a0
commit b5da98dcb7
3 changed files with 7 additions and 3 deletions

View File

@ -205,7 +205,7 @@ class MySQLRecordManager implements RecordManagerInterface {
} }
async createSchema(): Promise<void> { async createSchema(): Promise<void> {
const dataSource = await this.getDataSource('createSchema') const dataSource = await this.getDataSource()
try { try {
const queryRunner = dataSource.createQueryRunner() const queryRunner = dataSource.createQueryRunner()
const tableName = this.sanitizeTableName(this.tableName) const tableName = this.sanitizeTableName(this.tableName)

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()
} }
} }