use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class TimestampType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
String originalDefinition = StringUtils.trimToEmpty(getRawDefinition());
if (database instanceof MySQLDatabase) {
if (getRawDefinition().contains(" ") || getRawDefinition().contains("(")) {
return new DatabaseDataType(getRawDefinition());
}
return super.toDatabaseDataType(database);
}
if (database instanceof MSSQLDatabase) {
if (!LiquibaseConfiguration.getInstance().getProperty(GlobalConfiguration.class, GlobalConfiguration.CONVERT_DATA_TYPES).getValue(Boolean.class) && originalDefinition.toLowerCase().startsWith("timestamp")) {
return new DatabaseDataType(database.escapeDataTypeName("timestamp"));
}
return new DatabaseDataType(database.escapeDataTypeName("datetime"));
}
if (database instanceof SybaseDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("datetime"));
}
if (database instanceof DB2Database) {
Object[] parameters = getParameters();
if (parameters != null && parameters.length > 1) {
parameters = new Object[] { parameters[1] };
}
return new DatabaseDataType(database.escapeDataTypeName("timestamp"), parameters);
}
if (getAdditionalInformation() != null && (database instanceof PostgresDatabase || database instanceof OracleDatabase) || database instanceof HsqlDatabase) {
DatabaseDataType type = new DatabaseDataType("TIMESTAMP");
String additionalInformation = this.getAdditionalInformation();
if (additionalInformation != null && database instanceof PostgresDatabase) {
if (additionalInformation.toUpperCase().contains("TIMEZONE")) {
additionalInformation = additionalInformation.toUpperCase().replace("TIMEZONE", "TIME ZONE");
}
}
type.addAdditionalInformation(additionalInformation);
return type;
}
return super.toDatabaseDataType(database);
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class TinyIntType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof MSSQLDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("tinyint"));
}
if (database instanceof DerbyDatabase || database instanceof PostgresDatabase || database instanceof FirebirdDatabase || database instanceof DB2Database) {
return new DatabaseDataType("SMALLINT");
}
if (database instanceof MySQLDatabase) {
DatabaseDataType type = new DatabaseDataType("TINYINT", getParameters());
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if (database instanceof OracleDatabase) {
return new DatabaseDataType("NUMBER", 3);
}
return super.toDatabaseDataType(database);
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class BigIntType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof InformixDatabase) {
if (isAutoIncrement()) {
return new DatabaseDataType("SERIAL8");
} else {
return new DatabaseDataType("INT8");
}
}
if (database instanceof OracleDatabase) {
return new DatabaseDataType("NUMBER", 38, 0);
}
if (database instanceof MSSQLDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("bigint"));
}
if (database instanceof MySQLDatabase) {
DatabaseDataType type = new DatabaseDataType("BIGINT");
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if (database instanceof DB2Database || database instanceof DerbyDatabase || database instanceof HsqlDatabase || database instanceof FirebirdDatabase) {
return new DatabaseDataType("BIGINT");
}
if (database instanceof PostgresDatabase) {
if (isAutoIncrement()) {
return new DatabaseDataType("BIGSERIAL");
}
}
return super.toDatabaseDataType(database);
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class DateTimeType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
String originalDefinition = StringUtils.trimToEmpty(getRawDefinition());
boolean allowFractional = supportsFractionalDigits(database);
if (database instanceof DerbyDatabase || database instanceof FirebirdDatabase || database instanceof H2Database || database instanceof HsqlDatabase) {
return new DatabaseDataType("TIMESTAMP");
}
if (database instanceof DB2Database || database instanceof OracleDatabase) {
return new DatabaseDataType("TIMESTAMP", getParameters());
}
if (database instanceof MSSQLDatabase) {
Object[] parameters = getParameters();
if (originalDefinition.toLowerCase().startsWith("smalldatetime") || originalDefinition.toLowerCase().startsWith("[smalldatetime")) {
return new DatabaseDataType(database.escapeDataTypeName("smalldatetime"));
} else if (originalDefinition.equalsIgnoreCase("datetime2") || originalDefinition.equals("[datetime2]") || originalDefinition.matches("(?i)datetime2\\s*\\(.+") || originalDefinition.matches("\\[datetime2\\]\\s*\\(.+")) {
try {
if (database.getDatabaseMajorVersion() <= 9) {
//2005 or earlier
return new DatabaseDataType(database.escapeDataTypeName("datetime"));
}
}//assuming it is a newer version
catch (DatabaseException ignore) {
}
if (parameters.length == 0) {
parameters = new Object[] { 7 };
} else if (parameters.length > 1) {
parameters = new Object[] { parameters[1] };
}
return new DatabaseDataType(database.escapeDataTypeName("datetime2"), parameters);
}
return new DatabaseDataType(database.escapeDataTypeName("datetime"));
}
if (database instanceof InformixDatabase) {
// From database to changelog
if (getAdditionalInformation() == null || getAdditionalInformation().length() == 0) {
if (getParameters() != null && getParameters().length > 0) {
String parameter = String.valueOf(getParameters()[0]);
if ("4365".equals(parameter)) {
return new DatabaseDataType("DATETIME YEAR TO FRACTION(3)");
}
if ("3594".equals(parameter)) {
return new DatabaseDataType("DATETIME YEAR TO SECOND");
}
if ("3080".equals(parameter)) {
return new DatabaseDataType("DATETIME YEAR TO MINUTE");
}
if ("2052".equals(parameter)) {
return new DatabaseDataType("DATETIME YEAR TO DAY");
}
}
}
// From changelog to the database
if (getAdditionalInformation() != null && getAdditionalInformation().length() > 0) {
return new DatabaseDataType(originalDefinition);
}
return new DatabaseDataType("DATETIME YEAR TO FRACTION", 5);
}
if (database instanceof PostgresDatabase) {
String rawDefinition = originalDefinition.toLowerCase();
Object[] params = getParameters();
if (rawDefinition.contains("tz") || rawDefinition.contains("with time zone")) {
if (params.length == 0 || !allowFractional) {
return new DatabaseDataType("TIMESTAMP WITH TIME ZONE");
} else {
Object param = params[0];
if (params.length == 2) {
param = params[1];
}
return new DatabaseDataType("TIMESTAMP(" + param + ") WITH TIME ZONE");
}
} else {
if (params.length == 0 || !allowFractional) {
return new DatabaseDataType("TIMESTAMP WITHOUT TIME ZONE");
} else {
Object param = params[0];
if (params.length == 2) {
param = params[1];
}
return new DatabaseDataType("TIMESTAMP(" + param + ") WITHOUT TIME ZONE");
}
}
}
if (database instanceof SQLiteDatabase) {
return new DatabaseDataType("TEXT");
}
if (database instanceof MySQLDatabase) {
if (getParameters().length == 0 || !allowFractional) {
// fast out...
return new DatabaseDataType(getName());
}
Object[] params = getParameters();
Integer precision = Integer.valueOf(params[0].toString());
if (precision > 6) {
LogFactory.getInstance().getLog().warning("MySQL does not support a timestamp precision" + " of '" + precision + "' - resetting to" + " the maximum of '6'");
params = new Object[] { 6 };
}
return new DatabaseDataType(getName(), params);
}
return new DatabaseDataType(getName());
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class MediumIntType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof MSSQLDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("int"));
}
if (database instanceof MySQLDatabase) {
DatabaseDataType type = new DatabaseDataType("MEDIUMINT");
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if (database instanceof DB2Database || database instanceof DerbyDatabase || database instanceof FirebirdDatabase) {
//always smallint regardless of parameters passed
return new DatabaseDataType("MEDIUMINT");
}
return super.toDatabaseDataType(database);
}
Aggregations