Skip to content

Commit

Permalink
Merge pull request #358 from RJ-SMTR/hotfix/357-unaccent
Browse files Browse the repository at this point in the history
(prod) wilfix: preventive hotfix for unaccent
  • Loading branch information
williamfl2007 committed Jul 26, 2024
2 parents 1649fc2 + 15a39fb commit 19d3808
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { UsersModule } from './users/users.module';
import { TransacaoViewService } from './transacao-bq/transacao-view.service';
import { TransacaoViewModule } from './transacao-bq/transacao-view.module';
import { AppLoggerMiddleware } from './utils/logger-middleware';
import { AppService } from './app.service';

@Module({
imports: [
Expand Down Expand Up @@ -122,7 +123,7 @@ import { AppLoggerMiddleware } from './utils/logger-middleware';
SftpModule,
TransacaoViewModule,
],
providers: [TransacaoViewService],
providers: [TransacaoViewService, AppService],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
Expand Down
41 changes: 41 additions & 0 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { DataSource, Repository } from 'typeorm';
import { CustomLogger } from './utils/custom-logger';

@Injectable()
export class AppService implements OnModuleInit {
private logger: CustomLogger = new CustomLogger(AppService.name, {
timestamp: true,
});

constructor(@InjectDataSource() private dataSource: DataSource) {}

async onModuleInit() {
await this.applyHotfix();
}

async applyHotfix() {
const queryRunner = this.dataSource.createQueryRunner();
try {
this.logger.log('Applying preventive hotfix...');
await queryRunner.connect();
/**
* Unaccent
*
* Sometimes the unaccent extension is dropped with no reason so far.
* To prevent it, everytime Nest runs, it will re-install this extension.
*/
await queryRunner.query('DROP EXTENSION IF EXISTS unaccent');
await queryRunner.query('CREATE EXTENSION IF NOT EXISTS unaccent');
} catch (error) {
this.logger.error(
`Falha ao rodar o hotfix - ${error?.message}`,
error?.stack,
);
} finally {
await queryRunner.release();
this.logger.log('Preventive hotfix applied!');
}
}
}

0 comments on commit 19d3808

Please sign in to comment.