Skip to content

Commit

Permalink
* Fixed issue with missing index schema name when make "COMMENT ON" s…
Browse files Browse the repository at this point in the history
…tatement
  • Loading branch information
michaelsogos committed Oct 2, 2021
1 parent 004c888 commit 732162a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/api/CatalogApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ class CatalogApi {
result[fullTableName].indexes[index.indexname] = {
definition: index.indexdef,
comment: index.comment,
schema: table.schemaname,
};
});

Expand Down Expand Up @@ -602,6 +603,7 @@ class CatalogApi {
result[fullViewName].indexes[index.indexname] = {
definition: index.indexdef,
comment: index.comment,
schema: view.schemaname,
};
});

Expand Down
32 changes: 28 additions & 4 deletions src/api/CompareApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/sqlScriptGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/compareTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]));

Expand Down

0 comments on commit 732162a

Please sign in to comment.