Skip to content

Commit

Permalink
Merge branch 'release/4.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyUss committed Jul 26, 2019
2 parents 562c0a0 + b3c54ca commit 7e4b2ae
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 122 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ from MySQL to PostgreSQL as easy and smooth as possible.</p>
<b>Note:</b> "logs_directory" will be created during script execution.</p>

<h3>VERSION</h3>
<p>Current version is 4.0.0<br />
<p>Current version is 4.0.1<br />
(major version . improvements . bug fixes)</p>

<h3>KNOWN ISSUES</h3>
Expand Down
4 changes: 2 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"host" : "localhost",
"port" : 3306,
"database" : "test_db",
"charset" : "UTF8",
"charset" : "utf8mb4",
"user" : "root",
"password" : "0123456789"
},
Expand Down Expand Up @@ -82,7 +82,7 @@
"exclude_tables": [],

"include_tables_description": [
"List (Array) of tables, that will not be migrated.",
"List (Array) of tables, that will be migrated.",
"By default, nmig will migrate all tables."
],
"include_tables": [],
Expand Down
2 changes: 1 addition & 1 deletion config/test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"source" : {
"host" : "localhost",
"port" : 3306,
"charset" : "UTF8",
"charset" : "utf8mb4",
"database" : "nmig_test_db",
"user" : "root",
"password" : "0123456789"
Expand Down
96 changes: 52 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nmig",
"version": "4.0.0",
"version": "4.0.1",
"description": "The database migration app",
"author": "Anatoly Khaytovich<[email protected]>",
"license": "GPL-3.0",
Expand All @@ -12,17 +12,17 @@
"node": ">=8.0.0"
},
"dependencies": {
"mysql": "^2.16.0",
"pg": "^7.9.0",
"pg-copy-streams": "^2.2.0"
"mysql": "^2.17.1",
"pg": "^7.12.0",
"pg-copy-streams": "^2.2.2"
},
"devDependencies": {
"@types/mysql": "^2.15.5",
"@types/node": "^11.13.4",
"@types/mysql": "^2.15.6",
"@types/node": "^12.6.8",
"@types/pg": "^7.4.14",
"@types/tape": "^4.2.33",
"tape": "^4.10.1",
"typescript": "^3.4.3"
"tape": "^4.11.0",
"typescript": "^3.5.3"
},
"scripts": {
"build": "tsc",
Expand Down
7 changes: 4 additions & 3 deletions src/DataPipeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getSmallestDataChunkSizeInMb(conversion: Conversion): number {
/**
* Creates an array of indexes, that point to data chunks, that will be processed during current COPY operation.
*/
function fillBandwidth(conversion: Conversion): number[] {
async function fillBandwidth(conversion: Conversion): Promise<number[]> {
const dataChunkIndexes: number[] = [];

// Loop through the data pool from the beginning to the end.
Expand Down Expand Up @@ -113,7 +113,7 @@ function fillBandwidth(conversion: Conversion): number[] {

if (firstUnprocessedChunkIndex === -1) {
const msg: string = 'Something went wrong with DataPipeManager.';
log(conversion, msg, undefined, true);
await generateError(conversion, msg);
process.exit();
}

Expand All @@ -135,7 +135,8 @@ async function pipeData(conversion: Conversion, dataLoaderPath: string, options:
return processConstraints(conversion);
}

const chunksToLoad: any[] = fillBandwidth(conversion).map((index: number) => conversion._dataPool[index]);
const chunksIndexes: number[] = await fillBandwidth(conversion);
const chunksToLoad: any[] = chunksIndexes.map((index: number) => conversion._dataPool[index]);
const loaderProcess: ChildProcess = fork(dataLoaderPath, options);

loaderProcess.on('message', async (signal: any) => {
Expand Down
40 changes: 23 additions & 17 deletions src/FsOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function generateError(conversion: Conversion, message: string, sql: stri
return new Promise<void>(resolve => {
message += `\n\n\tSQL: ${sql}\n\n`;
const buffer: Buffer = Buffer.from(message, conversion._encoding);
log(conversion, message, undefined, true);
log(conversion, message, undefined);

fs.open(conversion._errorLogsPath, 'a', conversion._0777, (error: Error, fd: number) => {
if (error) {
Expand All @@ -48,13 +48,10 @@ export function generateError(conversion: Conversion, message: string, sql: stri
* Writes given log to the "/all.log" file.
* If necessary, writes given log to the "/{tableName}.log" file.
*/
export function log(conversion: Conversion, log: string | NodeJS.ErrnoException, tableLogPath?: string, isErrorLog?: boolean): void {
export function log(conversion: Conversion, log: string | NodeJS.ErrnoException, tableLogPath?: string): void {
console.log(log);
const buffer: Buffer = Buffer.from(`${ log }\n\n`, conversion._encoding);

if (!isErrorLog) {
console.log(log);
}

fs.open(conversion._allLogsPath, 'a', conversion._0777, (error: Error, fd: number) => {
if (!error) {
fs.write(fd, buffer, 0, buffer.length, null, () => {
Expand Down Expand Up @@ -124,28 +121,37 @@ export function readExtraConfig(config: any, baseDir: string): Promise<any> {
/**
* Creates logs directory.
*/
export function createLogsDirectory(conversion: Conversion): Promise<Conversion> {
return new Promise<Conversion>(resolve => {
const logTitle: string = 'FsOps::createLogsDirectory';
console.log(`\t--[${ logTitle }] Creating logs directory...`);
export async function createLogsDirectory(conversion: Conversion): Promise<Conversion> {
const logTitle: string = 'FsOps::createLogsDirectory';
await createDirectory(conversion, conversion._logsDirPath, logTitle);
await createDirectory(conversion, conversion._notCreatedViewsPath, logTitle);
return conversion;
}

/**
* Creates a directory at the specified path.
*/
function createDirectory(conversion: Conversion, directoryPath: string, logTitle: string): Promise<void> {
return new Promise<void>(resolve => {
console.log(`\t--[${ logTitle }] Creating directory ${ directoryPath }...`);

fs.stat(conversion._logsDirPath, (directoryDoesNotExist: Error, stat: fs.Stats) => {
fs.stat(directoryPath, (directoryDoesNotExist: Error, stat: fs.Stats) => {
if (directoryDoesNotExist) {
fs.mkdir(conversion._logsDirPath, conversion._0777, e => {
fs.mkdir(directoryPath, conversion._0777, e => {
if (e) {
console.log(`\t--[${ logTitle }] Cannot perform a migration due to impossibility to create "logs_directory": ${ conversion._logsDirPath }`);
console.log(`\t--[${ logTitle }] Cannot perform a migration due to impossibility to create directory: ${ directoryPath }`);
process.exit();
} else {
log(conversion, '\t--[logTitle] Logs directory is created...');
resolve(conversion);
log(conversion, `\t--[${ logTitle }] Directory ${ directoryPath } is created...`);
resolve();
}
});
} else if (!stat.isDirectory()) {
console.log(`\t--[${ logTitle }] Cannot perform a migration due to unexpected error`);
process.exit();
} else {
log(conversion, `\t--[${ logTitle }] Logs directory already exists...`);
resolve(conversion);
log(conversion, `\t--[${ logTitle }] Directory ${ directoryPath } already exists...`);
resolve();
}
});
});
Expand Down
Loading

0 comments on commit 7e4b2ae

Please sign in to comment.