mirror of
https://github.com/immich-app/immich.git
synced 2025-12-30 01:11:52 +03:00
fix(server): run migrations after database checks (#5832)
* run migrations after checks * optional migrations * only run checks in server and e2e * re-add migrations for microservices * refactor * move e2e init * remove assert from migration * update providers * update microservices app service * fixed logging * refactored version check, added unit tests * more version tests * don't use mocks for sut * refactor tests * suggest image only if postgres is 14, 15 or 16 * review suggestions * fixed regexp escape * fix typing * update migration
This commit is contained in:
10
server/test/repositories/database.repository.mock.ts
Normal file
10
server/test/repositories/database.repository.mock.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { IDatabaseRepository, Version } from '@app/domain';
|
||||
|
||||
export const newDatabaseRepositoryMock = (): jest.Mocked<IDatabaseRepository> => {
|
||||
return {
|
||||
getExtensionVersion: jest.fn(),
|
||||
getPostgresVersion: jest.fn().mockResolvedValue(new Version(14, 0, 0)),
|
||||
createExtension: jest.fn().mockImplementation(() => Promise.resolve()),
|
||||
runMigrations: jest.fn(),
|
||||
};
|
||||
};
|
||||
@@ -5,6 +5,7 @@ export * from './asset.repository.mock';
|
||||
export * from './audit.repository.mock';
|
||||
export * from './communication.repository.mock';
|
||||
export * from './crypto.repository.mock';
|
||||
export * from './database.repository.mock';
|
||||
export * from './job.repository.mock';
|
||||
export * from './library.repository.mock';
|
||||
export * from './machine-learning.repository.mock';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AssetCreate, IJobRepository, JobItem, JobItemHandler, LibraryResponseDto, QueueName } from '@app/domain';
|
||||
import { AppModule } from '@app/immich';
|
||||
import { dataSource, databaseChecks } from '@app/infra';
|
||||
import { dataSource } from '@app/infra';
|
||||
import { AssetEntity, AssetType, LibraryType } from '@app/infra/entities';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
@@ -24,7 +24,9 @@ export interface ResetOptions {
|
||||
}
|
||||
export const db = {
|
||||
reset: async (options?: ResetOptions) => {
|
||||
await databaseChecks();
|
||||
if (!dataSource.isInitialized) {
|
||||
await dataSource.initialize();
|
||||
}
|
||||
await dataSource.transaction(async (em) => {
|
||||
const entities = options?.entities || [];
|
||||
const tableNames =
|
||||
@@ -87,10 +89,7 @@ export const testApp = {
|
||||
|
||||
app = await moduleFixture.createNestApplication().init();
|
||||
await app.listen(0);
|
||||
|
||||
if (jobs) {
|
||||
await app.get(AppService).init();
|
||||
}
|
||||
await app.get(AppService).init();
|
||||
|
||||
const port = app.getHttpServer().address().port;
|
||||
const protocol = app instanceof Server ? 'https' : 'http';
|
||||
@@ -99,6 +98,7 @@ export const testApp = {
|
||||
return app;
|
||||
},
|
||||
reset: async (options?: ResetOptions) => {
|
||||
await app.get(AppService).init();
|
||||
await db.reset(options);
|
||||
},
|
||||
teardown: async () => {
|
||||
|
||||
Reference in New Issue
Block a user