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

[LB-1373] fixed precision for time type for PostgreSQL #1894

Merged
merged 7 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -56,17 +56,24 @@ public DatabaseDataType toDatabaseDataType(Database database) {
}

if (database instanceof PostgresDatabase) {
DatabaseDataType datatype = new DatabaseDataType(getName(), getValidatedParameters());
String rawDefinition = originalDefinition.toLowerCase(Locale.US);
if (rawDefinition.contains("tz") || rawDefinition.contains("with time zone")) {
return new DatabaseDataType("TIME WITH TIME ZONE");
datatype.addAdditionalInformation("WITH TIME ZONE");
} else {
return new DatabaseDataType("TIME WITHOUT TIME ZONE");
datatype.addAdditionalInformation("WITHOUT TIME ZONE");
}
return datatype;
}

return new DatabaseDataType(getName());
}

Object[] getValidatedParameters() {
Object[] parameters = getParameters();
return (parameters.length > 0 && (Integer.parseInt(getParameters()[0].toString()) <= 6)) ? parameters : new Object[0];
}

@Override
public String objectToSql(Object value, Database database) {
if ((value == null) || "null".equals(value.toString().toLowerCase(Locale.US))) {
Expand Down
@@ -0,0 +1,29 @@
package liquibase.datatype.core

import liquibase.database.core.*
import liquibase.exception.UnexpectedLiquibaseException
import spock.lang.Specification
import spock.lang.Unroll

class TimeTypeTest extends Specification {
@Unroll
def "toDatabaseType"() {
when:
def type = new TimeType()
for (param in params) {
type.addParameter(param)
}

then:
type.toDatabaseDataType(database).toString() == expected

where:
params | database | expected
[] | new PostgresDatabase() | "time WITHOUT TIME ZONE"
[0] | new PostgresDatabase() | "time(0) WITHOUT TIME ZONE"
[6] | new PostgresDatabase() | "time(6) WITHOUT TIME ZONE"
[7] | new PostgresDatabase() | "time WITHOUT TIME ZONE"
[] | new MySQLDatabase() | "time"

}
}