Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: version history is case sensitive, and fails when customers chan… #1782

Merged
merged 4 commits into from
Dec 3, 2020

Conversation

prb112
Copy link
Contributor

@prb112 prb112 commented Dec 3, 2020

…ge the case sensisitivity of their schema names

Signed-off-by: Paul Bastide pbastide@us.ibm.com

…ge the case sensisitivity of their schema names

Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
@@ -59,7 +59,7 @@ public GetLatestVersionDAO(String adminSchemaName, String schemaName) {
ps.setString(2, schemaName);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String schema = rs.getString(1);
String schema = rs.getString(1).toUpperCase();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I threw this in as uppercase for consistency

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance note: using WHERE UPPER(my_col) = ... can have performance implications because it often means that you can't use an index (on my_col). But in this case, it's unlikely to have a significant impact, because the row counts are relatively low.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point.

@@ -50,7 +50,7 @@ public GetLatestVersionDAO(String adminSchemaName, String schemaName) {
final String cols = DataDefinitionUtil.join(SchemaConstants.SCHEMA_NAME, SchemaConstants.OBJECT_TYPE, SchemaConstants.OBJECT_NAME);
final String sql = "SELECT " + cols
+ ", max(" + SchemaConstants.VERSION + ") FROM " + tbl
+ " WHERE " + SchemaConstants.SCHEMA_NAME + " IN (?, ?) "
+ " WHERE UCASE(" + SchemaConstants.SCHEMA_NAME + ") IN (UCASE(?), UCASE(?)) "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrapped this in ucase for backwards compatiblity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swapped to UPPER

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should UCASE(?) the args like that...because it suggests you don't know what case the args are. We should be making sure the args are upper-case before that (because it's probably important for equals and HashMap lookups in other places). The first place I'd force case is when we parse the CLI argument in Main.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - I sort of agree, However there is an inconsistency across versions I'd like too account for, also schema names in postgres tend to be lowercase versus uppercase in db2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking normalizing casing here was critical for backwards compatibility. If there is an existing version history service value thats been saved as lowercase, we need the new uppercase schema name to match it, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I do that when we process the result sets down further on in

Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
@prb112 prb112 linked an issue Dec 3, 2020 that may be closed by this pull request
Copy link
Collaborator

@punktilious punktilious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've made a mental note that we probably need some unit tests around the schema name handling and version history stuff.

Copy link
Member

@lmsurpre lmsurpre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema case changes cause DuplicateNameException with Schema Tool
3 participants