From 732162a232e9f65be9da9c8331e0f49414a5884b Mon Sep 17 00:00:00 2001 From: Michael Sogos Date: Sat, 2 Oct 2021 12:38:25 +0200 Subject: [PATCH] * Fixed issue with missing index schema name when make "COMMENT ON" statement --- src/api/CatalogApi.js | 2 ++ src/api/CompareApi.js | 32 ++++++++++++++++++++++++++++---- src/sqlScriptGenerator.js | 4 +++- test/compareTest.js | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/api/CatalogApi.js b/src/api/CatalogApi.js index 1365bcc..20cb013 100644 --- a/src/api/CatalogApi.js +++ b/src/api/CatalogApi.js @@ -488,6 +488,7 @@ class CatalogApi { result[fullTableName].indexes[index.indexname] = { definition: index.indexdef, comment: index.comment, + schema: table.schemaname, }; }); @@ -602,6 +603,7 @@ class CatalogApi { result[fullViewName].indexes[index.indexname] = { definition: index.indexdef, comment: index.comment, + schema: view.schemaname, }; }); diff --git a/src/api/CompareApi.js b/src/api/CompareApi.js index ab292d1..fddf289 100644 --- a/src/api/CompareApi.js +++ b/src/api/CompareApi.js @@ -580,21 +580,45 @@ class CompareApi { sqlScript.push(sql.generateDropIndexScript(index)); } sqlScript.push(`\n${sourceTableIndexes[index].definition};\n`); - sqlScript.push(sql.generateChangeCommentScript(objectType.INDEX, index, sourceTableIndexes[index].comment)); + sqlScript.push( + sql.generateChangeCommentScript( + objectType.INDEX, + `"${sourceTableIndexes[index].schema}"."${index}"`, + sourceTableIndexes[index].comment + ) + ); } else { if (droppedIndexes.includes(index)) { //It will recreate a dropped index because changes happens on involved columns sqlScript.push(`\n${sourceTableIndexes[index].definition};\n`); - sqlScript.push(sql.generateChangeCommentScript(objectType.INDEX, index, sourceTableIndexes[index].comment)); + sqlScript.push( + sql.generateChangeCommentScript( + objectType.INDEX, + `"${sourceTableIndexes[index].schema}"."${index}"`, + sourceTableIndexes[index].comment + ) + ); } else { if (sourceTableIndexes[index].comment != targetTableIndexes[index].comment) - sqlScript.push(sql.generateChangeCommentScript(objectType.INDEX, index, sourceTableIndexes[index].comment)); + sqlScript.push( + sql.generateChangeCommentScript( + objectType.INDEX, + `"${sourceTableIndexes[index].schema}"."${index}"`, + sourceTableIndexes[index].comment + ) + ); } } } else { //Table index not exists on target database, then generate script to add index sqlScript.push(`\n${sourceTableIndexes[index].definition};\n`); - sqlScript.push(sql.generateChangeCommentScript(objectType.INDEX, index, sourceTableIndexes[index].comment)); + sqlScript.push( + sql.generateChangeCommentScript( + objectType.INDEX, + `"${sourceTableIndexes[index].schema}"."${index}"`, + sourceTableIndexes[index].comment + ) + ); } } diff --git a/src/sqlScriptGenerator.js b/src/sqlScriptGenerator.js index be995fc..ba2bc8d 100644 --- a/src/sqlScriptGenerator.js +++ b/src/sqlScriptGenerator.js @@ -188,7 +188,9 @@ var helper = { let indexesComment = []; for (let index in schema.indexes) { - indexesComment.push(this.generateChangeCommentScript(objectType.INDEX, index, schema.indexes[index].comment)); + indexesComment.push( + this.generateChangeCommentScript(objectType.INDEX, `"${schema.indexes[index].schema}"."${index}"`, schema.indexes[index].comment) + ); } let script = `\nCREATE TABLE IF NOT EXISTS ${table} (\n\t${columns.join(",\n\t")}\n)${options};\n${indexes.join("\n")}\n${privileges.join( diff --git a/test/compareTest.js b/test/compareTest.js index 7fd72fc..8d43ac2 100644 --- a/test/compareTest.js +++ b/test/compareTest.js @@ -15,7 +15,7 @@ Config.compareOptions.schemaCompare.dropMissingFunction = true; Config.compareOptions.schemaCompare.dropMissingAggregate = true; Config.compareOptions.dataCompare.enable = true; -Config.compareOptions.dataCompare.tables.push(new TableDefinition("test_generic", ["id","a_camelCaseField"])); +Config.compareOptions.dataCompare.tables.push(new TableDefinition("test_generic", ["id","a_camelCaseField","a_string_array2"])); Config.compareOptions.dataCompare.tables.push(new TableDefinition("test_columnd_def_value", ["id"])); Config.compareOptions.dataCompare.tables.push(new TableDefinition("diff_test", ["id"]));