Skip to content

Commit

Permalink
removed unnecessary interactive terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyUss committed Oct 28, 2020
1 parent f05d403 commit 389bedc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 55 deletions.
76 changes: 26 additions & 50 deletions src/BootProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import DBVendors from './DBVendors';
import IDBAccessQueryParams from './IDBAccessQueryParams';
import IConfAndLogsPaths from './IConfAndLogsPaths';
import { getStateLogsTableName } from './MigrationStateManager';
import { generateError, log } from './FsOps';

/**
* Checks correctness of connection details of both MySQL and PostgreSQL.
Expand Down Expand Up @@ -67,61 +68,36 @@ export const getLogo = (): string => {
/**
* Boots the migration.
*/
export const boot = (conversion: Conversion): Promise<Conversion> => {
return new Promise<Conversion>(async resolve => {
const connectionErrorMessage = await checkConnection(conversion);
const logo: string = getLogo();
export const boot = async (conversion: Conversion): Promise<Conversion> => {
const connectionErrorMessage = await checkConnection(conversion);
const logo: string = getLogo();
const logTitle: string = 'BootProcessor::boot';

if (connectionErrorMessage) {
console.log(`${ logo } \n ${ connectionErrorMessage }`);
process.exit(1);
}
if (connectionErrorMessage) {
await generateError(conversion, `\t--[${ logTitle }]\n ${ logo } \n ${ connectionErrorMessage }`);
process.exit(1);
}

const sql: string = `SELECT EXISTS(SELECT 1 FROM information_schema.tables`
+ ` WHERE table_schema = '${ conversion._schema }' AND table_name = '${ getStateLogsTableName(conversion, true) }');`;
const sql: string = `SELECT EXISTS(SELECT 1 FROM information_schema.tables`
+ ` WHERE table_schema = '${ conversion._schema }' AND table_name = '${ getStateLogsTableName(conversion, true) }');`;

const params: IDBAccessQueryParams = {
conversion: conversion,
caller: 'BootProcessor::boot',
sql: sql,
vendor: DBVendors.PG,
processExitOnError: true,
shouldReturnClient: false
};

const result: DBAccessQueryResult = await DBAccess.query(params);
const isExists: boolean = !!result.data.rows[0].exists;
const message: string = `${ (isExists
? '\n\t--[boot] NMIG is ready to restart after some failure.\n\t--[boot] Consider checking log files at the end of migration.'
: '\n\t--[boot] NMIG is ready to start.') } \n\t--[boot] Proceed? [Y/n]`;

console.log(logo + message);

const _getUserInput = (input: string): void => {
const trimedInput: string = input.trim();

if (trimedInput === 'n' || trimedInput === 'N') {
console.log('\t--[boot] Migration aborted.\n');
process.exit(0);
}

if (trimedInput === 'y' || trimedInput === 'Y') {
process.stdin.removeListener('data', _getUserInput);
conversion._timeBegin = new Date();
return resolve(conversion);
}

const hint: string = `\t--[boot] Unexpected input ${ trimedInput }\n`
+ `\t--[boot] Expected input is upper case Y\n\t--[boot] or lower case n\n${message}`;
const params: IDBAccessQueryParams = {
conversion: conversion,
caller: 'BootProcessor::boot',
sql: sql,
vendor: DBVendors.PG,
processExitOnError: true,
shouldReturnClient: false
};

console.log(hint);
};
const result: DBAccessQueryResult = await DBAccess.query(params);
const isExists: boolean = !!result.data.rows[0].exists;
const message: string = `${ (isExists
? '\n\t--[boot] NMIG is restarting after some failure.\n\t--[boot] Consider checking log files at the end of migration.\n'
: '\n\t--[boot] NMIG is starting.') } \n`;

process.stdin
.resume()
.setEncoding(conversion._encoding)
.on('data', _getUserInput);
});
log(conversion, `\t--[${ logTitle }] ${ logo }${ message }`);
return conversion;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class Conversion {
/**
* The timestamp, at which the migration began.
*/
public _timeBegin: Date | null;
public _timeBegin: Date;

/**
* Current version of source (MySQL) db.
Expand Down Expand Up @@ -216,7 +216,7 @@ export default class Conversion {
this._notCreatedViewsPath = path.join(this._logsDirPath, 'not_created_views');
this._excludeTables = this._config.exclude_tables === undefined ? [] : this._config.exclude_tables;
this._includeTables = this._config.include_tables === undefined ? [] : this._config.include_tables;
this._timeBegin = null;
this._timeBegin = new Date();
this._encoding = this._config.encoding === undefined ? 'utf8' : this._config.encoding;
this._0777 = '0777';
this._mysqlVersion = '5.6.21'; // Simply a default value.
Expand Down
2 changes: 1 addition & 1 deletion src/FsOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const readDataAndIndexTypesMap = async (conversion: Conversion): Promise<
const logTitle: string = 'FsOps::readDataAndIndexTypesMap';
conversion._dataTypesMap = await readAndParseJsonFile(conversion._dataTypesMapAddr);
conversion._indexTypesMap = await readAndParseJsonFile(conversion._indexTypesMapAddr);
console.log(`\t--[${ logTitle }] Data and Index Types Maps are loaded...`);
log(conversion, `\t--[${ logTitle }] Data and Index Types Maps are loaded...`);
return conversion;
};

Expand Down
4 changes: 2 additions & 2 deletions src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const { confPath, logsPath } = getConfAndLogsPaths();
readConfig(confPath, logsPath)
.then(config => readExtraConfig(config, confPath))
.then(Conversion.initializeConversion)
.then(boot)
.then(readDataAndIndexTypesMap)
.then(createLogsDirectory)
.then(readDataAndIndexTypesMap)
.then(boot)
.then(createSchema)
.then(createStateLogsTable)
.then(createDataPoolTable)
Expand Down

0 comments on commit 389bedc

Please sign in to comment.