-
Notifications
You must be signed in to change notification settings - Fork 17
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
Handle Timezone Differences in Liquibase for Cloud Spanner #385
Handle Timezone Differences in Liquibase for Cloud Spanner #385
Conversation
@@ -49,12 +57,26 @@ public boolean dataTypeIsNotModifiable(final String typeName) { | |||
|
|||
@Override | |||
public String getDateLiteral(final String isoDate) { | |||
String literal = super.getDateLiteral(isoDate); | |||
String literal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just remove this variable. It is not really needed in the way that the implementation works now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
String formattedTime = utcDateTime.format(ISO_LOCAL_TIME); | ||
literal = "TIMESTAMP '" + formattedDate + "T" + formattedTime + "Z'"; | ||
} catch (ParseException e) { | ||
throw new RuntimeException("Error parsing ISO date: " + isoDate, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to do the same as the super class does in a case like this, which is to return "BAD_DATE_FORMAT:" + isoDate;
. I don't know exactly why Liquibase does that here, but as the super class does not throw an exception for an invalid value, we should probably also not do in this override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did like super class
OffsetDateTime utcDateTime = instant.atOffset(ZoneOffset.UTC); | ||
String formattedDate = utcDateTime.format(ISO_LOCAL_DATE); | ||
String formattedTime = utcDateTime.format(ISO_LOCAL_TIME); | ||
literal = "TIMESTAMP '" + formattedDate + "T" + formattedTime + "Z'"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just return directly here instead of assigning to literal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (isDateTime(isoDate)) { | ||
literal = "TIMESTAMP " + literal.replace(' ', 'T'); | ||
Date date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move this inside the try block to what is now line 66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct, the super class already has similar behavior, and the try catch block was needed for the ISODateFormat().parse(isoDate) method.
literal = super.getDateLiteral(isoDate); | ||
literal = "DATE " + literal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just do return "DATE " + super.getDateLiteral(isoDate);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments resolved
To ensure predictable behavior, adjustments were made to handle timezone differences appropriately and align Liquibase's behavior with Cloud Spanner's expectations.