Skip to content

Commit 1b26f12

Browse files
committed
fix: fix db resfresh
1 parent 6569fc8 commit 1b26f12

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/auth/local.strategy.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Strategy } from 'passport-local';
22
import { PassportStrategy } from '@nestjs/passport';
3-
import {
4-
ForbiddenException,
5-
Inject,
6-
Injectable,
7-
UnauthorizedException,
8-
} from '@nestjs/common';
3+
import { ForbiddenException, Inject, Injectable } from '@nestjs/common';
94
import { AuthService } from './auth.service';
105

116
@Injectable()

src/maintenance/database-manager.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,26 @@ export class DatabaseManager {
3939
return this.execute(em, this.createSchemaQuery);
4040
}
4141

42-
async refresh(em: EntityManager): Promise<void> {
42+
async refresh(em: EntityManager, attempt?: number): Promise<void> {
4343
// TODO: add transaction here
44-
// sore some reason, thi.em.transactional fails with sqlite
45-
await this.dropSchema(em);
46-
await this.createSchema(em);
47-
await this.seed(em);
44+
// for some reason, thi.em.transactional fails with sqlite
45+
// Not the best solution, but it seems to work
46+
try {
47+
await this.dropSchema(em);
48+
await this.createSchema(em);
49+
await this.seed(em);
50+
} catch {
51+
if (attempt < 10) {
52+
return new Promise((resolve, reject) => {
53+
setTimeout(() => {
54+
this.refresh(em, attempt + 1)
55+
.then(resolve)
56+
.catch(reject);
57+
}, 100);
58+
});
59+
} else {
60+
throw new Error('Error on database refresh');
61+
}
62+
}
4863
}
4964
}

src/maintenance/maintenance.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { MaintenanceService } from './maintenance.service';
99
import { AdminGuard } from '../common/guards/admin.guard';
1010

11-
@ApiTags('maintenance')
11+
@ApiTags('Maintenance')
1212
@Controller('maintenance')
1313
export class MaintenanceController {
1414
constructor(private readonly maintenanceService: MaintenanceService) {}

0 commit comments

Comments
 (0)