Skip to content

Commit

Permalink
Merge branch 'LB-34' into 3.10.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Jul 21, 2020
2 parents d965dba + 4b5d5c8 commit c367493
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
import liquibase.util.StringUtils;
import liquibase.util.grammar.ParseException;

import java.util.Locale;

/**
* Data type support for TIMESTAMP data types in various DBMS. All DBMS are at least expected to support the
* year, month, day, hour, minute and second parts. Optionally, fractional seconds and time zone information can be
* specified as well.
*/
@DataTypeInfo(name = "timestamp", aliases = {"java.sql.Types.TIMESTAMP", "java.sql.Timestamp", "timestamptz"}, minParameters = 0, maxParameters = 1, priority = LiquibaseDataType.PRIORITY_DEFAULT)
@DataTypeInfo(name = "timestamp", aliases = {"java.sql.Types.TIMESTAMP", "java.sql.Types.TIMESTAMP_WITH_TIMEZONE", "java.sql.Timestamp", "timestamptz"}, minParameters = 0, maxParameters = 1, priority = LiquibaseDataType.PRIORITY_DEFAULT)
public class TimestampType extends DateTimeType {

/**
Expand Down Expand Up @@ -121,6 +119,21 @@ public DatabaseDataType toDatabaseDataType(Database database) {
type = new DatabaseDataType("TIMESTAMP");
}

if (originalDefinition.startsWith("java.sql.Types.TIMESTAMP_WITH_TIMEZONE")
&& (database instanceof PostgresDatabase
|| database instanceof OracleDatabase
|| database instanceof H2Database
|| database instanceof HsqlDatabase)) {

if (database instanceof PostgresDatabase || database instanceof H2Database) {
type.addAdditionalInformation("WITH TIME ZONE");
} else {
type.addAdditionalInformation("WITH TIMEZONE");
}

return type;
}

if (getAdditionalInformation() != null
&& (database instanceof PostgresDatabase
|| database instanceof OracleDatabase)
Expand All @@ -130,7 +143,7 @@ public DatabaseDataType toDatabaseDataType(Database database) {

if (additionalInformation != null) {
String additionInformation = additionalInformation.toUpperCase(Locale.US);
if ((database instanceof PostgresDatabase) && additionInformation.toUpperCase(Locale.US).contains("TIMEZONE")) {
if ((database instanceof PostgresDatabase || database instanceof H2Database) && additionInformation.toUpperCase(Locale.US).contains("TIMEZONE")) {
additionalInformation = additionInformation.toUpperCase(Locale.US).replace("TIMEZONE", "TIME ZONE");
}
// CORE-3229 Oracle 11g doesn't support WITHOUT clause in TIMESTAMP data type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,50 @@ class DataTypeFactoryTest extends Specification {
"nclob" | new OracleDatabase() | "NCLOB" | ClobType | false
"xml" | new OracleDatabase() | "XMLTYPE" | XMLType | false
"xmltype" | new OracleDatabase() | "XMLTYPE" | XMLType | false
"timestamp" | new OracleDatabase() | "TIMESTAMP" | TimestampType | false
"timestamp(6)" | new OracleDatabase() | "TIMESTAMP(6)" | TimestampType | false
"TIMESTAMP WITH TIMEZONE" | new OracleDatabase() | "TIMESTAMP WITH TIMEZONE" | TimestampType | false
"TIMESTAMP(6) WITH TIMEZONE" | new OracleDatabase() | "TIMESTAMP(6) WITH TIMEZONE" | TimestampType | false
"timestamp without timezone" | new OracleDatabase() | "TIMESTAMP" | TimestampType | false
"timestamp(6) without timezone" | new OracleDatabase() | "TIMESTAMP(6)" | TimestampType | false
"timestamptz" | new OracleDatabase() | "TIMESTAMP" | TimestampType | false
"timestamptz(6)" | new OracleDatabase() | "TIMESTAMP(6)" | TimestampType | false
"java.sql.Timestamp" | new OracleDatabase() | "TIMESTAMP" | TimestampType | false
"java.sql.Timestamp(6)" | new OracleDatabase() | "TIMESTAMP(6)" | TimestampType | false
"java.sql.Types.TIMESTAMP" | new OracleDatabase() | "TIMESTAMP" | TimestampType | false
"java.sql.Types.TIMESTAMP(6)" | new OracleDatabase() | "TIMESTAMP(6)" | TimestampType | false
"java.sql.Types.TIMESTAMP_WITH_TIMEZONE" | new OracleDatabase() | "TIMESTAMP WITH TIMEZONE" | TimestampType | false
"java.sql.Types.TIMESTAMP_WITH_TIMEZONE(6)" | new OracleDatabase() | "TIMESTAMP(6) WITH TIMEZONE" | TimestampType | false
"xml" | new PostgresDatabase() | "XML" | XMLType | false
"timestamp" | new PostgresDatabase() | "TIMESTAMP WITHOUT TIME ZONE" | TimestampType | false
"timestamp(6)" | new PostgresDatabase() | "TIMESTAMP(6) WITHOUT TIME ZONE" | TimestampType | false
"timestamp with timezone" | new PostgresDatabase() | "TIMESTAMP WITH TIME ZONE" | TimestampType | false
"timestamp(6) with timezone" | new PostgresDatabase() | "TIMESTAMP(6) WITH TIME ZONE" | TimestampType | false
"timestamp without timezone" | new PostgresDatabase() | "TIMESTAMP WITHOUT TIME ZONE" | TimestampType | false
"timestamp(6) without timezone" | new PostgresDatabase() | "TIMESTAMP(6) WITHOUT TIME ZONE" | TimestampType | false
"timestamptz" | new PostgresDatabase() | "TIMESTAMP WITH TIME ZONE" | TimestampType | false
"timestamptz(6)" | new PostgresDatabase() | "TIMESTAMP(6) WITH TIME ZONE" | TimestampType | false
"java.sql.Timestamp" | new PostgresDatabase() | "TIMESTAMP WITHOUT TIME ZONE" | TimestampType | false
"java.sql.Timestamp(6)" | new PostgresDatabase() | "TIMESTAMP(6) WITHOUT TIME ZONE" | TimestampType | false
"java.sql.Types.TIMESTAMP" | new PostgresDatabase() | "TIMESTAMP WITHOUT TIME ZONE" | TimestampType | false
"java.sql.Types.TIMESTAMP(6)" | new PostgresDatabase() | "TIMESTAMP(6) WITHOUT TIME ZONE" | TimestampType | false
"java.sql.Types.TIMESTAMP_WITH_TIMEZONE" | new PostgresDatabase() | "TIMESTAMP WITH TIME ZONE" | TimestampType | false
"java.sql.Types.TIMESTAMP_WITH_TIMEZONE(6)" | new PostgresDatabase() | "TIMESTAMP(6) WITH TIME ZONE" | TimestampType | false
"BINARY(16)" | new H2Database() | "BINARY(16)" | BlobType | false
"timestamp" | new H2Database() | "TIMESTAMP" | TimestampType | false
"timestamp(6)" | new H2Database() | "TIMESTAMP(6)" | TimestampType | false
"TIMESTAMP WITH TIMEZONE" | new H2Database() | "TIMESTAMP WITH TIME ZONE" | TimestampType | false
"TIMESTAMP(6) WITH TIMEZONE" | new H2Database() | "TIMESTAMP(6) WITH TIME ZONE" | TimestampType | false
"timestamp without timezone" | new H2Database() | "TIMESTAMP" | TimestampType | false
"timestamp(6) without timezone" | new H2Database() | "TIMESTAMP(6)" | TimestampType | false
"timestamptz" | new H2Database() | "TIMESTAMP" | TimestampType | false
"timestamptz(6)" | new H2Database() | "TIMESTAMP(6)" | TimestampType | false
"java.sql.Timestamp" | new H2Database() | "TIMESTAMP" | TimestampType | false
"java.sql.Timestamp(6)" | new H2Database() | "TIMESTAMP(6)" | TimestampType | false
"java.sql.Types.TIMESTAMP" | new H2Database() | "TIMESTAMP" | TimestampType | false
"java.sql.Types.TIMESTAMP(6)" | new H2Database() | "TIMESTAMP(6)" | TimestampType | false
"java.sql.Types.TIMESTAMP_WITH_TIMEZONE" | new H2Database() | "TIMESTAMP WITH TIME ZONE" | TimestampType | false
"java.sql.Types.TIMESTAMP_WITH_TIMEZONE(6)" | new H2Database() | "TIMESTAMP(6) WITH TIME ZONE" | TimestampType | false
}

@Unroll("#featureName: #object for #database")
Expand Down

0 comments on commit c367493

Please sign in to comment.