AnatolyUss / nmig

NMIG is a database migration tool, written in Node.js and highly inspired by FromMySqlToPostgreSql.
GNU General Public License v3.0
451 stars 83 forks source link

forcing postgresql column names to lowercase #121

Open jschneid-nmdp opened 11 months ago

jschneid-nmdp commented 11 months ago

For my story, the schemas for both the (source) MySQL and (final target) PostgreSQL databases are defined by third-party software.

The two schemas are generally compatible, but the MySQL schema uses uppercase column names, and the final target PostgreSQL schema uses lowercase column names.

Due to other minor PostgreSQL schema discrepancies, I'm first using NMIG to migrate the MySQL data into a NMIG target PostgreSQL database and then using pg_dump --data-only to extract data that can be loaded into the (final target) PostgreSQL database.

The extract-and-load process using pg_dump doesn't work when the NMIG target PostgreSQL database has uppercase column names (because the final target PostgreSQL database has lowercase column names).

To get past this problem, I made a one-line change to ExtraConfigProcessor.ts, modifying the getColumnName function to force all column names in the NMIG target PostgreSQL database to lowercase.

diff --git a/src/ExtraConfigProcessor.ts b/src/ExtraConfigProcessor.ts
index da5fa74..0d8fc22 100644
--- a/src/ExtraConfigProcessor.ts
+++ b/src/ExtraConfigProcessor.ts
@@ -87,7 +87,7 @@ export const getColumnName = (
         }
     }

-    return retVal;
+    return retVal.toLowerCase();
 };

 /**

This hack was enough to solve my problem. Not sure if this story is unusual, or whether it might make sense to think about adding a general NMIG configuration setting to force lowercase column names in the target db.

jonfreeland commented 10 months ago

Did you see #106? That seems to do what you're looking for, albeit undocumented.

jschneid-nmdp commented 10 months ago

Interesting. I remember making a half-hearted attempt to use that, but I eventually found it easier to hack the code and not use extraConfig.