From 9d68dd9185182efd8a7c88d06ae7725b14ba6288 Mon Sep 17 00:00:00 2001 From: zhi Date: Sun, 27 Oct 2024 12:04:04 +0800 Subject: [PATCH 1/2] Fix foreign key comparison case sensitive SQL keywords are case insensitive although they are often written in all caps. Object return from node-sql-parser is actually case sensitive based on the imported sql, thus "foreign key" doesn't work as expected. --- src/utils/importSQL/mysql.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/importSQL/mysql.js b/src/utils/importSQL/mysql.js index f8b3715..075b378 100644 --- a/src/utils/importSQL/mysql.js +++ b/src/utils/importSQL/mysql.js @@ -105,7 +105,7 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) { } }); }); - } else if (d.constraint_type === "FOREIGN KEY") { + } else if (d.constraint_type.toLowerCase() === "foreign key") { const relationship = {}; const startTableId = table.id; const startTable = e.table[0].table; @@ -187,7 +187,7 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) { e.expr.forEach((expr) => { if ( expr.action === "add" && - expr.create_definitions.constraint_type === "FOREIGN KEY" + expr.create_definitions.constraint_type.toLowerCase() === "foreign key" ) { const relationship = {}; const startTable = e.table[0].table; From dcf73e6f95ba6176c735a592b3ae70b98d831dff Mon Sep 17 00:00:00 2001 From: zhi Date: Sun, 27 Oct 2024 20:27:47 +0800 Subject: [PATCH 2/2] Fix remaining case sensitive foreign key comparison --- src/utils/importSQL/mariadb.js | 4 ++-- src/utils/importSQL/mssql.js | 4 ++-- src/utils/importSQL/postgres.js | 4 ++-- src/utils/importSQL/sqlite.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/importSQL/mariadb.js b/src/utils/importSQL/mariadb.js index 563200e..0bcf4a1 100644 --- a/src/utils/importSQL/mariadb.js +++ b/src/utils/importSQL/mariadb.js @@ -105,7 +105,7 @@ export function fromMariaDB(ast, diagramDb = DB.GENERIC) { } }); }); - } else if (d.constraint_type === "FOREIGN KEY") { + } else if (d.constraint_type.toLowerCase() === "foreign key") { const relationship = {}; const startTableId = table.id; const startTable = e.table[0].table; @@ -187,7 +187,7 @@ export function fromMariaDB(ast, diagramDb = DB.GENERIC) { e.expr.forEach((expr) => { if ( expr.action === "add" && - expr.create_definitions.constraint_type === "FOREIGN KEY" + expr.create_definitions.constraint_type.toLowerCase() === "foreign key" ) { const relationship = {}; const startTable = e.table[0].table; diff --git a/src/utils/importSQL/mssql.js b/src/utils/importSQL/mssql.js index 740f744..71d6510 100644 --- a/src/utils/importSQL/mssql.js +++ b/src/utils/importSQL/mssql.js @@ -117,7 +117,7 @@ export function fromMSSQL(ast, diagramDb = DB.GENERIC) { } }); }); - } else if (d.constraint_type === "FOREIGN KEY") { + } else if (d.constraint_type.toLowerCase() === "foreign key") { const relationship = {}; const startTableId = table.id; const startTable = e.table[0].table; @@ -199,7 +199,7 @@ export function fromMSSQL(ast, diagramDb = DB.GENERIC) { e.expr.forEach((expr) => { if ( expr.action === "add" && - expr.create_definitions.constraint_type === "FOREIGN KEY" + expr.create_definitions.constraint_type.toLowerCase() === "foreign key" ) { const relationship = {}; const startTable = e.table[0].table; diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js index 2912404..1cdb126 100644 --- a/src/utils/importSQL/postgres.js +++ b/src/utils/importSQL/postgres.js @@ -105,7 +105,7 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { } }); }); - } else if (d.constraint_type === "FOREIGN KEY") { + } else if (d.constraint_type.toLowerCase() === "foreign key") { const relationship = {}; const startTableId = table.id; const startTable = e.table[0].table; @@ -278,7 +278,7 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { e.expr.forEach((expr) => { if ( expr.action === "add" && - expr.create_definitions.constraint_type === "FOREIGN KEY" + expr.create_definitions.constraint_type.toLowerCase() === "foreign key" ) { const relationship = {}; const startTable = e.table[0].table; diff --git a/src/utils/importSQL/sqlite.js b/src/utils/importSQL/sqlite.js index 5bd3a1b..9c89a4a 100644 --- a/src/utils/importSQL/sqlite.js +++ b/src/utils/importSQL/sqlite.js @@ -122,7 +122,7 @@ export function fromSQLite(ast, diagramDb = DB.GENERIC) { } }); }); - } else if (d.constraint_type === "FOREIGN KEY") { + } else if (d.constraint_type.toLowerCase() === "foreign key") { const relationship = {}; const startTableId = table.id; const startTable = e.table[0].table;