fix(server): auto-reconnect to database (#12320)

This commit is contained in:
Jason Rasmussen
2024-09-04 13:32:43 -04:00
committed by GitHub
parent 1783dfd393
commit 12b65e3c24
10 changed files with 130 additions and 46 deletions

View File

@@ -31,6 +31,19 @@ export class DatabaseRepository implements IDatabaseRepository {
this.logger.setContext(DatabaseRepository.name);
}
async reconnect() {
try {
if (this.dataSource.isInitialized) {
await this.dataSource.destroy();
}
const { isInitialized } = await this.dataSource.initialize();
return isInitialized;
} catch (error) {
this.logger.error(`Database connection failed: ${error}`);
return false;
}
}
async getExtensionVersion(extension: DatabaseExtension): Promise<ExtensionVersion> {
const [res]: ExtensionVersion[] = await this.dataSource.query(
`SELECT default_version as "availableVersion", installed_version as "installedVersion"

View File

@@ -3,7 +3,7 @@ import { isLogLevelEnabled } from '@nestjs/common/services/utils/is-log-level-en
import { ClsService } from 'nestjs-cls';
import { LogLevel } from 'src/config';
import { ILoggerRepository } from 'src/interfaces/logger.interface';
import { LogColor } from 'src/utils/logger-colors';
import { LogColor } from 'src/utils/logger';
const LOG_LEVELS = [LogLevel.VERBOSE, LogLevel.DEBUG, LogLevel.LOG, LogLevel.WARN, LogLevel.ERROR, LogLevel.FATAL];