Browse Source

fix(migrations): always run migrations in dev environment

master
jamaljsr 5 years ago
parent
commit
4149e76fdd
  1. 12
      src/lib/docker/dockerService.spec.ts
  2. 3
      src/lib/docker/dockerService.ts

12
src/lib/docker/dockerService.spec.ts

@ -12,7 +12,7 @@ import { networksPath } from 'utils/config';
import { APP_VERSION, defaultRepoState, DOCKER_REPO } from 'utils/constants';
import * as files from 'utils/files';
import { createNetwork } from 'utils/network';
import { getNetwork, testManagedImages } from 'utils/tests';
import { getNetwork, mockProperty, testManagedImages } from 'utils/tests';
jest.mock('dockerode');
jest.mock('os');
@ -359,6 +359,16 @@ describe('DockerService', () => {
});
});
it('should not run migrations in production with up to date version', async () => {
mockProperty(process, 'env', { NODE_ENV: 'production' } as any);
const file = createCurrentNetworksFile();
filesMock.exists.mockResolvedValue(true);
filesMock.read.mockResolvedValue(JSON.stringify(file));
const result = await dockerService.loadNetworks();
expect(result).toEqual(file);
mockProperty(process, 'env', { NODE_ENV: 'test' } as any);
});
it('should not modify a current network if migrated', async () => {
const file = createCurrentNetworksFile();
file.version = '0.0.0'; // induce a migration to run

3
src/lib/docker/dockerService.ts

@ -200,7 +200,8 @@ class DockerService implements DockerLibrary {
const json = await read(path);
let data = JSON.parse(json);
info(`loaded ${data.networks.length} networks from '${path}'`);
if (data.version !== APP_VERSION) {
// migrate data when the version differs or running locally
if (data.version !== APP_VERSION || process.env.NODE_ENV !== 'production') {
data = migrateNetworksFile(data);
await this.saveNetworks(data);
}

Loading…
Cancel
Save