Skip to content

Commit 1239adc

Browse files
author
arthosofteq
authored
Merge pull request #410 from RedisInsight/rename_to_v2
add migration old data to the new home directory
2 parents 358abea + a9b669b commit 1239adc

File tree

8 files changed

+54
-9
lines changed

8 files changed

+54
-9
lines changed

redisinsight/api/config/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const homedir = join(__dirname, '..');
55
const buildInfoFileName = 'build.json';
66
const dataZipFileName = 'data.zip';
77

8-
98
const staticDir = process.env.BUILD_TYPE === 'ELECTRON' && process['resourcesPath']
109
? join(process['resourcesPath'], 'static')
1110
: join(__dirname, '..', 'static');
@@ -17,6 +16,7 @@ const defaultsDir = process.env.BUILD_TYPE === 'ELECTRON' && process['resourcesP
1716
export default {
1817
dir_path: {
1918
homedir,
19+
prevHomedir: homedir,
2020
staticDir,
2121
defaultsDir,
2222
logs: join(homedir, 'logs'),

redisinsight/api/config/production.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { join } from 'path';
22
import * as os from 'os';
33

44
const homedir = process.env.APP_FOLDER_ABSOLUTE_PATH
5-
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-preview'));
5+
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-v2'));
6+
7+
const prevHomedir = join(os.homedir(), '.redisinsight-preview');
68

79
export default {
810
dir_path: {
911
homedir,
12+
prevHomedir,
1013
logs: join(homedir, 'logs'),
1114
customPlugins: join(homedir, 'plugins'),
1215
commands: join(homedir, 'commands'),

redisinsight/api/config/staging.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { join } from 'path';
22
import * as os from 'os';
33

44
const homedir = process.env.APP_FOLDER_ABSOLUTE_PATH
5-
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-v2.0-stage'));
5+
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-v2-stage'));
6+
7+
const prevHomedir = join(os.homedir(), '.redisinsight-v2.0-stage');
68

79
export default {
810
dir_path: {
911
homedir,
12+
prevHomedir,
1013
logs: join(homedir, 'logs'),
1114
customPlugins: join(homedir, 'plugins'),
1215
commands: join(homedir, 'commands'),

redisinsight/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redisinsight-api",
3-
"version": "2.0.0",
3+
"version": "2.0.5",
44
"description": "RedisInsight API",
55
"private": true,
66
"author": {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as fs from 'fs-extra';
2+
import config from 'src/utils/config';
3+
import { join } from 'path';
4+
5+
const PATH_CONFIG = config.get('dir_path');
6+
const DB_CONFIG = config.get('db');
7+
8+
/**
9+
* Copy source if exists
10+
* @param source
11+
* @param destination
12+
*/
13+
const copySource = async (source, destination) => {
14+
if (await fs.pathExists(source)) {
15+
await fs.copy(source, destination).catch();
16+
}
17+
};
18+
19+
/**
20+
* Migrate data from previous home folder defined in configs
21+
*/
22+
export const migrateHomeFolder = async () => {
23+
try {
24+
if (!(await fs.pathExists(DB_CONFIG.database)) && await fs.pathExists(PATH_CONFIG.prevHomedir)) {
25+
await fs.ensureDir(PATH_CONFIG.homedir);
26+
27+
await Promise.all([
28+
'redisinsight.db',
29+
'plugins',
30+
].map((target) => copySource(
31+
join(PATH_CONFIG.prevHomedir, target),
32+
join(PATH_CONFIG.homedir, target),
33+
)));
34+
}
35+
} catch (e) {
36+
// continue initialization even without migration
37+
}
38+
};

redisinsight/api/src/main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import 'dotenv/config'
1+
import 'dotenv/config';
22
import { NestFactory } from '@nestjs/core';
33
import { SwaggerModule } from '@nestjs/swagger';
44
import { NestApplicationOptions } from '@nestjs/common';
55
import * as bodyParser from 'body-parser';
66
import { WinstonModule } from 'nest-winston';
77
import { GlobalExceptionFilter } from 'src/exceptions/global-exception.filter';
8+
import { get } from 'src/utils';
9+
import { migrateHomeFolder } from 'src/init-helper';
810
import { AppModule } from './app.module';
911
import SWAGGER_CONFIG from '../config/swagger';
1012
import LOGGER_CONFIG from '../config/logger';
11-
import config from './utils/config';
1213

1314
export default async function bootstrap() {
14-
const serverConfig = config.get('server');
15+
await migrateHomeFolder();
16+
17+
const serverConfig = get('server');
1518
const port = process.env.API_PORT || serverConfig.port;
1619
const logger = WinstonModule.createLogger(LOGGER_CONFIG);
1720

redisinsight/api/test/test-runs/docker.build.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
APP_DATA_HOMEDIR=/root/.redisinsight-v2.0
21
COV_FOLDER=./coverage
32
ID=defaultid
43
RTE=defaultrte
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
APP_DATA_HOMEDIR=/root/.redisinsight-2.0
21
COV_FOLDER=./coverage
32
ID=defaultid
43
RTE=defaultrte

0 commit comments

Comments
 (0)