Skip to content

Commit 06417d1

Browse files
authored
Feature/fix lower case all column names option (#131)
* fixed 'lowerCaseAllColumnNames' option * updated nmig version * updated dependencies * updated configuration * fixed comment
1 parent 3b31651 commit 06417d1

8 files changed

+1098
-548
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Or, if you have moved <code>config</code> folder out from Nmig's directory:<br /
109109
<br /><b>Note:</b> "logs_directory" will be created during script execution.</p>
110110

111111
<h3>VERSION</h3>
112-
<p>Current version is 6.1.0</p>
112+
<p>Current version is 6.1.1</p>
113113

114114
<h3>LICENSE</h3>
115115
<p>NMIG is available under "GNU GENERAL PUBLIC LICENSE" (v. 3) <br />

config/config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"source" : {
1515
"host" : "127.0.0.1",
1616
"port" : 3306,
17-
"database" : "test_db",
17+
"database" : "sample_stuff",
1818
"charset" : "utf8mb4",
1919
"supportBigNumbers": true,
2020
"user" : "root",
@@ -31,7 +31,7 @@
3131
"target" : {
3232
"host" : "127.0.0.1",
3333
"port" : 5432,
34-
"database" : "test_db",
34+
"database" : "sample_stuff",
3535
"charset" : "UTF8",
3636
"user" : "postgres",
3737
"password" : "0123456789"

config/extra_config.json

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
"If you don't need to rename neither tables nor columns, then remove the 'tables' section."
2222
],
2323

24+
"README_lowerCaseAllColumnNames": [
25+
"'lowerCaseAllColumnNames', once set true, instructs nmig to rename/lowercase all columns in all tables.",
26+
"By default, 'lowerCaseAllColumnNames' is false.",
27+
"Note, 're-namings' defined below under 'tables' -> 'columns' will take precedence over 'lowerCaseAllColumnNames: true'."
28+
],
29+
"lowerCaseAllColumnNames": false,
30+
2431
"tables" : [
2532
{
2633
"name" : {

package-lock.json

+1,045-504
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nmig",
3-
"version": "6.1.0",
3+
"version": "6.1.1",
44
"description": "The database migration app",
55
"author": "Anatoly Khaytovich<[email protected]>",
66
"license": "GPL-3.0",
@@ -12,30 +12,31 @@
1212
"node": ">=18.16.1"
1313
},
1414
"dependencies": {
15-
"@types/node": "20.4.4",
16-
"@types/uuid": "9.0.2",
17-
"@types/pg": "8.10.2",
18-
"@types/pg-copy-streams": "1.2.2",
15+
"@types/node": "22.5.1",
16+
"@types/uuid": "10.0.0",
17+
"@types/pg": "8.11.8",
18+
"@types/pg-copy-streams": "1.2.5",
1919
"json2csv": "5.0.7",
20-
"mysql2": "3.5.2",
21-
"pg": "8.11.1",
20+
"mysql2": "3.11.0",
21+
"pg": "8.12.0",
2222
"pg-copy-streams": "6.0.6",
23-
"uuid": "9.0.0"
23+
"uuid": "10.0.0"
2424
},
2525
"devDependencies": {
26-
"@types/tape": "5.6.0",
26+
"@types/tape": "5.6.4",
2727
"@typescript-eslint/eslint-plugin": "5.61.0",
2828
"@typescript-eslint/parser": "5.61.0",
2929
"eslint": "8.44.0",
3030
"prettier": "3.0.0",
31-
"tape": "5.6.6",
32-
"typescript": "5.1.6"
31+
"tape": "5.8.1",
32+
"typescript": "5.5.4"
3333
},
3434
"scripts": {
3535
"build": "tsc --incremental -p tsconfig.json",
3636
"lint": "npx eslint . --ext .ts",
3737
"format": "npx prettier . --ignore-path ./.prettierignore --write && git status",
3838
"flb": "npm run format && npm run lint && npm run build",
39+
"fb": "npm run format && npm run build",
3940
"start": "node dist/src/Main.js",
4041
"test": "node dist/test/Main.test.js"
4142
},

src/Conversion.ts

+6-17
Original file line numberDiff line numberDiff line change
@@ -232,32 +232,21 @@ export default class Conversion {
232232
this._allLogsPath = path.join(this._logsDirPath, 'all.log');
233233
this._errorLogsPath = path.join(this._logsDirPath, 'errors-only.log');
234234
this._notCreatedViewsPath = path.join(this._logsDirPath, 'not_created_views');
235-
this._excludeTables =
236-
this._config.exclude_tables === undefined ? [] : this._config.exclude_tables;
237-
this._includeTables =
238-
this._config.include_tables === undefined ? [] : this._config.include_tables;
235+
this._excludeTables = this._config.exclude_tables || [];
236+
this._includeTables = this._config.include_tables || [];
239237
this._timeBegin = new Date();
240-
this._encoding = this._config.encoding === undefined ? 'utf8' : this._config.encoding;
238+
this._encoding = this._config.encoding || 'utf8';
241239
this._0777 = '0777';
242240
this._mysqlVersion = '5.6.21'; // Simply a default value.
243-
this._extraConfig =
244-
this._config.extraConfig === undefined ? false : this._config.extraConfig;
241+
this._extraConfig = this._config.extraConfig;
245242
this._tablesToMigrate = [];
246243
this._viewsToMigrate = [];
247244
this._dataPool = [];
248245
this._dicTables = new Map<string, Table>();
249246
this._mySqlDbName = this._sourceConString.database;
247+
this._streamsHighWaterMark = +(this._config.streams_high_water_mark || 16384);
250248

251-
this._streamsHighWaterMark =
252-
this._config.streams_high_water_mark === undefined
253-
? 16384
254-
: +this._config.streams_high_water_mark;
255-
256-
this._schema =
257-
this._config.schema === undefined || this._config.schema === ''
258-
? this._mySqlDbName
259-
: this._config.schema;
260-
249+
this._schema = this._config.schema || this._mySqlDbName;
261250
const isValidMaxEachDbConnectionPoolSize: boolean =
262251
this._config.max_each_db_connection_pool_size !== undefined &&
263252
Conversion._isIntNumeric(this._config.max_each_db_connection_pool_size);

src/DataChunksProcessor.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default async (
4343
tableName,
4444
true,
4545
);
46+
4647
const logTitle = 'DataChunksProcessor::default';
4748
const arrTableColumns = (conversion._dicTables.get(tableName) as Table).arrTableColumns;
4849
const selectFieldList: string = arrangeColumnsData(
@@ -76,7 +77,16 @@ export default async (
7677
_rowsCnt: rowsCnt,
7778
_selectFieldList: selectFieldList,
7879
_copyColumnNamesList: arrTableColumns
79-
.map((column: any): string => `"${column.Field}"`)
80+
.map((column: any): string => {
81+
const columnName = extraConfigProcessor.getColumnName(
82+
conversion,
83+
originalTableName,
84+
column.Field,
85+
false,
86+
);
87+
88+
return `"${columnName}"`;
89+
})
8090
.join(','),
8191
});
8292

src/ExtraConfigProcessor.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,35 @@ export const getTableName = (
4747

4848
/**
4949
* Retrieves current column's name.
50+
*
51+
* !!!Note, 're-namings' defined in extra-config under 'tables' -> 'columns'
52+
* will take precedence over 'lowerCaseAllColumnNames: true'.
5053
*/
5154
export const getColumnName = (
5255
conversion: Conversion,
5356
originalTableName: string,
5457
currentColumnName: string,
5558
shouldGetOriginal: boolean,
5659
): string => {
57-
let retVal: string = currentColumnName;
58-
59-
if (conversion._extraConfig !== null) {
60+
if (conversion._extraConfig) {
6061
if ('tables' in conversion._extraConfig) {
6162
for (let i = 0; i < conversion._extraConfig.tables.length; ++i) {
62-
const isOriginal: boolean =
63+
const tableFound: boolean =
6364
conversion._extraConfig.tables[i].name.original === originalTableName &&
6465
'columns' in conversion._extraConfig.tables[i];
6566

66-
if (isOriginal) {
67+
if (tableFound) {
6768
for (
6869
let columnsCount = 0;
6970
columnsCount < conversion._extraConfig.tables[i].columns.length;
7071
++columnsCount
7172
) {
72-
if (
73+
const columnFound: boolean =
7374
conversion._extraConfig.tables[i].columns[columnsCount].original ===
74-
currentColumnName
75-
) {
76-
retVal = shouldGetOriginal
75+
currentColumnName;
76+
77+
if (columnFound) {
78+
return shouldGetOriginal
7779
? conversion._extraConfig.tables[i].columns[columnsCount].original
7880
: conversion._extraConfig.tables[i].columns[columnsCount].new;
7981
}
@@ -82,12 +84,12 @@ export const getColumnName = (
8284
}
8385
}
8486

85-
if (conversion._extraConfig.lowerCaseAllColumnNames && !shouldGetOriginal) {
86-
retVal = retVal.toLowerCase();
87+
if (conversion._extraConfig.lowerCaseAllColumnNames) {
88+
return currentColumnName.toLowerCase();
8789
}
8890
}
8991

90-
return retVal;
92+
return currentColumnName;
9193
};
9294

9395
/**

0 commit comments

Comments
 (0)