feat(server): env variable to skip migrations on startup (#9069)

* env variable to skip migrations

* update docs

* update env doc
This commit is contained in:
Mert
2024-04-24 22:52:38 -04:00
committed by GitHub
parent f0f9053115
commit 466451abc9
6 changed files with 29 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ export const immichAppConfig: ConfigModuleOptions = {
DB_DATABASE_NAME: WHEN_DB_URL_SET,
DB_URL: Joi.string().optional(),
DB_VECTOR_EXTENSION: Joi.string().optional().valid('pgvector', 'pgvecto.rs').default('pgvecto.rs'),
DB_SKIP_MIGRATIONS: Joi.boolean().optional().default(false),
MACHINE_LEARNING_PORT: Joi.number().optional(),
MICROSERVICES_PORT: Joi.number().optional(),

View File

@@ -12,6 +12,7 @@ describe(DatabaseService.name, () => {
let loggerMock: Mocked<ILoggerRepository>;
beforeEach(() => {
delete process.env.DB_SKIP_MIGRATIONS;
databaseMock = newDatabaseRepositoryMock();
loggerMock = newLoggerRepositoryMock();
sut = new DatabaseService(databaseMock, loggerMock);
@@ -210,5 +211,13 @@ describe(DatabaseService.name, () => {
expect(loggerMock.fatal).not.toHaveBeenCalled();
},
);
it('should skip migrations if DB_SKIP_MIGRATIONS=true', async () => {
process.env.DB_SKIP_MIGRATIONS = 'true';
await expect(sut.init()).resolves.toBeUndefined();
expect(databaseMock.runMigrations).not.toHaveBeenCalled();
});
});
});

View File

@@ -49,7 +49,9 @@ export class DatabaseService {
throw error;
}
await this.databaseRepository.runMigrations();
if (process.env.DB_SKIP_MIGRATIONS !== 'true') {
await this.databaseRepository.runMigrations();
}
});
}