Skip to content

Commit

Permalink
Merge branch '4.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
nvoxland committed Oct 5, 2020
2 parents 85f71ff + b435da2 commit c1da538
Show file tree
Hide file tree
Showing 43 changed files with 647 additions and 101 deletions.
27 changes: 24 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
Liquibase Core Changelog
===========================================

Changes in version 4.1.0
Changes in version 3.10.3

- GH PR#912 - CORE-3379 escaping postgres questionmark operators to prevent unwanted parameter syntax
- GH PR#936 - SpringLiquibase createResourceOpener() now returns a ResourceAccessor, which allows it to be overridden with any kind of ResourceAccessor
- GH PR#983 - Fixes for loadData to support Postgres enums with java.sql.Types.OTHER
- GH PR#1010 - Potential fix for generated columns on postgres
- GH PR#1258 - Reduced the verbosity of logging by moving SQL logging from info to debug logging
- GH PR#1239 - Fix xsd, remove surplus space after validateForeignKey
- GH PR#1296 - Put the banner in an external file for easier editing.
- GH PR#1327 - Fix varchar(max) extrainfo in 3.10 branch
- GH PR#1406 - Fixed integration tests for 983
- GH PR#781 - feat: Maven Liquibase Plugin generateChangeLog mysql sql comment supported
- GH PR#945 - [CORE-3523] Consistently map Liquibase integer types to Oracle integer types. MERGED THEN UNMERGED
- GH PR#1140 - fix root paths for spring boot fat jar
- GH PR#1332 - Update FileSystemResourceAccessor.java
- GH PR#1372 - Fix for PR 1001 in 3.10.x branch
- Fixed priority for JDBC Connections
- GH PR#1140 - Added json and sql to the list
- GH PR#1418 - Revert "[CORE-3523] Consistently map Liquibase integer types to Oracle integer types" UNMERGE 945
- GH PR#1422 - Updates for #1081 in 3.10.x
- GH PR#1431 - Fix merge issue in OracleDatabase

Changes in version 4.1.0 (2020.9.28)

- Added support for hub.liquibase.com to CLI and Maven integrations
- New registerChangeLog command
Expand All @@ -25,14 +46,14 @@ Changes in version 3.10.2 (2020.7.27)
- GH PR#1177 - CORE-3643: fixed the 'shouldValidateX' methods in the Constraints
- GH PR#1201 - H2 unknown reserved word


Changes in version 4.0.0 (2020.07.14)
- No changes since 4.0.0 beta2

Changes in version 4.0.0 Beta2 (2020.07.1)
- Re-introduced deprecated versions of commonly used 3.x methods that had been removed for 4.0
- Fix to handle --logLevel=debug/fine CLI argument
- Do not include root filesystem in default CLI search paths

Changes in version 3.10.1 (2020.7.2)

- GH PR#913 - [CORE-3471] Fixed NPE in LiquibaseUtil when MANIFEST.MF doesn't contain Bundle-Version or Build-Time
Expand Down
6 changes: 6 additions & 0 deletions liquibase-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.stefanbirkner</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.PostgresDatabase;
import liquibase.exception.DatabaseException;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.exception.ValidationErrors;
Expand Down Expand Up @@ -240,8 +241,11 @@ public SqlStatement[] generateStatements(Database database) {
}
for (String statement : StringUtil.processMutliLineSQL(processedSQL, isStripComments(), isSplitStatements(), getEndDelimiter())) {
if (database instanceof MSSQLDatabase) {
statement = statement.replaceAll("\\n", "\r\n");
}
statement = statement.replaceAll("\\n", "\r\n");
}
if (database instanceof PostgresDatabase) {
statement = statement.replaceAll("(^|[^\\?])\\?(?!\\?)(?=([^']*'[^']*')*[^']*$)", "$1??");
}

String escapedStatement = statement;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public SqlStatement[] generateStatements(Database database) {
Object defaultValue = column.getDefaultValueObject();

LiquibaseDataType columnType = DataTypeFactory.getInstance().fromDescription(column.getType() + (isAutoIncrement ? "{autoIncrement:true}" : ""), database);
isAutoIncrement |= columnType.isAutoIncrement();
if ((constraints != null) && (constraints.isPrimaryKey() != null) && constraints.isPrimaryKey()) {
statement.addPrimaryKeyColumn(column.getName(), columnType, defaultValue, constraints.getValidatePrimaryKey(),
constraints.getPrimaryKeyName(),constraints.getPrimaryKeyTablespace());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ public void setColumns(List<LoadDataColumnConfig> columns) {
public SqlStatement[] generateStatements(Database database) {
boolean databaseSupportsBatchUpdates = false;
try {
databaseSupportsBatchUpdates = database.supportsBatchUpdates();
if (database instanceof PostgresDatabase) {
databaseSupportsBatchUpdates = false;
}
else {
databaseSupportsBatchUpdates = database.supportsBatchUpdates();
}
} catch (DatabaseException e) {
throw new UnexpectedLiquibaseException(e);
}
Expand Down Expand Up @@ -330,13 +335,6 @@ public SqlStatement[] generateStatements(Database database) {
ColumnConfig valueConfig = new ColumnConfig();

ColumnConfig columnConfig = getColumnConfig(i, headers[i].trim());

//
// Always set the type for the valueConfig if the value is NULL
//
if ("NULL".equalsIgnoreCase(value.toString())) {
valueConfig.setType(columnConfig.getType());
}
if (columnConfig != null) {
if ("skip".equalsIgnoreCase(columnConfig.getType())) {
continue;
Expand All @@ -347,6 +345,12 @@ public SqlStatement[] generateStatements(Database database) {
columnName = columnConfig.getName();
}

//
// Always set the type for the valueConfig if the value is NULL
//
if ("NULL".equalsIgnoreCase(value.toString())) {
valueConfig.setType(columnConfig.getType());
}
valueConfig.setName(columnName);

if (columnConfig.getType() != null) {
Expand All @@ -369,7 +373,8 @@ public SqlStatement[] generateStatements(Database database) {
columnConfig.getType().toLowerCase().contains("date")
|| columnConfig.getType().toLowerCase().contains("time")
) {
if ("NULL".equalsIgnoreCase(value.toString())) {
if ("NULL".equalsIgnoreCase(value.toString()) ||
"".equals(value.toString())) {
valueConfig.setValue(null);
} else {
try {
Expand Down Expand Up @@ -436,6 +441,13 @@ public SqlStatement[] generateStatements(Database database) {
} else {
valueConfig.setValue(value.toString());
}
} else if (columnConfig.getType().equalsIgnoreCase(LOAD_DATA_TYPE.OTHER.toString())) {
valueConfig.setType(columnConfig.getType());
if ("NULL".equalsIgnoreCase(value.toString())) {
valueConfig.setValue(null);
} else {
valueConfig.setValue(value.toString());
}
} else {
throw new UnexpectedLiquibaseException(
String.format(coreBundle.getString("loaddata.type.is.not.supported"),
Expand Down Expand Up @@ -467,10 +479,8 @@ public SqlStatement[] generateStatements(Database database) {
// 2. The database supports batched statements (for improved performance) AND we are not in an
// "SQL" mode (i.e. we generate an SQL file instead of actually modifying the database).
if
((needsPreparedStatement || (databaseSupportsBatchUpdates &&
Scope.getCurrentScope().getSingleton(ExecutorService.class).executorExists("logging", database) &&
!(Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("logging", database) instanceof LoggingExecutor))) &&
hasPreparedStatementsImplemented()) {
((needsPreparedStatement || (databaseSupportsBatchUpdates && ! isLoggingExecutor(database) &&
hasPreparedStatementsImplemented()))) {
anyPreparedStatements = true;
ExecutablePreparedStatementBase stmt =
this.createPreparedStatement(
Expand Down Expand Up @@ -563,6 +573,12 @@ database, getCatalogName(), getSchemaName(),
}
}

private boolean isLoggingExecutor(Database database) {
final ExecutorService executorService = Scope.getCurrentScope().getSingleton(ExecutorService.class);

return executorService.executorExists("logging", database) &&
(executorService.getExecutor("logging", database) instanceof LoggingExecutor);
}
/**
* Iterate through the List of LoadDataColumnConfig and ask the database for any column types that we have
* no data type of.
Expand Down Expand Up @@ -824,6 +840,6 @@ public String getSerializedObjectNamespace() {

@SuppressWarnings("HardCodedStringLiteral")
public enum LOAD_DATA_TYPE {
BOOLEAN, NUMERIC, DATE, STRING, COMPUTED, SEQUENCE, BLOB, CLOB, SKIP,UUID
BOOLEAN, NUMERIC, DATE, STRING, COMPUTED, SEQUENCE, BLOB, CLOB, SKIP,UUID, OTHER
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
package liquibase.database.core;

import static java.util.ResourceBundle.getBundle;

import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import liquibase.CatalogAndSchema;
import liquibase.Scope;
import liquibase.database.AbstractJdbcDatabase;
Expand All @@ -42,6 +23,14 @@
import liquibase.util.JdbcUtils;
import liquibase.util.StringUtil;

import java.lang.reflect.Method;
import java.sql.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.ResourceBundle.getBundle;

/**
* Encapsulates Oracle database support.
*/
Expand Down Expand Up @@ -87,7 +76,7 @@ public int getPriority() {
return PRIORITY_DEFAULT;
}

private final void tryProxySession(final String url, final Connection con) {
private void tryProxySession(final String url, final Connection con) {
Matcher m = PROXY_USER.matcher(url);
if (m.matches()) {
Properties props = new Properties();
Expand All @@ -104,8 +93,6 @@ private final void tryProxySession(final String url, final Connection con) {

@Override
public void setConnection(DatabaseConnection conn) {
//noinspection HardCodedStringLiteral,HardCodedStringLiteral,HardCodedStringLiteral,HardCodedStringLiteral,
// HardCodedStringLiteral
//noinspection HardCodedStringLiteral,HardCodedStringLiteral,HardCodedStringLiteral,HardCodedStringLiteral,
// HardCodedStringLiteral
reservedWords.addAll(Arrays.asList("GROUP", "USER", "SESSION", "PASSWORD", "RESOURCE", "START", "SIZE", "UID", "DESC", "ORDER")); //more reserved words not returned by driver
Expand Down Expand Up @@ -147,17 +134,15 @@ public void setConnection(DatabaseConnection conn) {
//cannot set it. That is OK
}

Statement statement = null;
ResultSet resultSet = null;
CallableStatement statement = null;
try {
statement = sqlConn.createStatement();
//noinspection HardCodedStringLiteral
resultSet = statement.executeQuery("SELECT value FROM v$parameter WHERE name = 'compatible'");
String compatibleVersion = null;
if (resultSet.next()) {
//noinspection HardCodedStringLiteral
compatibleVersion = resultSet.getString("value");
}
statement = sqlConn.prepareCall("{call DBMS_UTILITY.DB_VERSION(?,?)}");
statement.registerOutParameter(1, Types.VARCHAR);
statement.registerOutParameter(2, Types.VARCHAR);
statement.execute();

String compatibleVersion = statement.getString(2);
if (compatibleVersion != null) {
Matcher majorVersionMatcher = Pattern.compile("(\\d+)\\.(\\d+)\\..*").matcher(compatibleVersion);
if (majorVersionMatcher.matches()) {
Expand All @@ -166,12 +151,12 @@ public void setConnection(DatabaseConnection conn) {
}
}
} catch (SQLException e) {
@SuppressWarnings("HardCodedStringLiteral") String message = "Cannot read from v$parameter: " + e.getMessage();
@SuppressWarnings("HardCodedStringLiteral") String message = "Cannot read from DBMS_UTILITY.DB_VERSION: " + e.getMessage();

//noinspection HardCodedStringLiteral
Scope.getCurrentScope().getLog(getClass()).info("Could not set check compatibility mode on OracleDatabase, assuming not running in any sort of compatibility mode: " + message);
} finally {
JdbcUtils.close(resultSet, statement);
JdbcUtils.closeStatement(statement);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import liquibase.exception.DatabaseException;
import liquibase.listener.SqlListener;
import liquibase.servicelocator.LiquibaseService;
import liquibase.servicelocator.LiquibaseService;
import liquibase.util.JdbcUtils;

import java.sql.Connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import liquibase.exception.DatabaseException;
import liquibase.listener.SqlListener;
import liquibase.servicelocator.LiquibaseService;
import liquibase.servicelocator.LiquibaseService;
import liquibase.util.JdbcUtils;

import java.sql.Connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,8 @@ protected String formatNumber(String value) {
*/
public abstract LoadDataChange.LOAD_DATA_TYPE getLoadTypeName();

public boolean isAutoIncrement() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class BigIntType extends LiquibaseDataType {

private boolean autoIncrement;

@Override
public boolean isAutoIncrement() {
return autoIncrement;
}
Expand Down
30 changes: 24 additions & 6 deletions liquibase-core/src/main/java/liquibase/datatype/core/ClobType.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ public DatabaseDataType toDatabaseDataType(Database database) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("varchar"));
// If there is additional specification after ntext (e.g. COLLATE), import that.
String originalExtraInfo = originalDefinition.replaceFirst("^(?i)\\[?text\\]?\\s*", "");
type.addAdditionalInformation("(max)"
+ (StringUtil.isEmpty(originalExtraInfo) ? "" : " " + originalExtraInfo));
type.addAdditionalInformation("(max)");
if(!StringUtil.isEmpty(originalExtraInfo)) {
//if we still have something like (25555) remove it
//since we already set it to max, otherwise add collate or other info
if(originalExtraInfo.lastIndexOf(")") < (originalExtraInfo.length() - 1)) {
type.addAdditionalInformation(originalExtraInfo.substring(originalExtraInfo.lastIndexOf(")") + 1));
}
}
return type;
}
}
Expand All @@ -67,8 +73,14 @@ public DatabaseDataType toDatabaseDataType(Database database) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("varchar"));
// If there is additional specification after ntext (e.g. COLLATE), import that.
String originalExtraInfo = originalDefinition.replaceFirst("^(?i)\\[?text\\]?\\s*", "");
type.addAdditionalInformation("(max)"
+ (StringUtil.isEmpty(originalExtraInfo) ? "" : " " + originalExtraInfo));
type.addAdditionalInformation("(max)");
if(!StringUtil.isEmpty(originalExtraInfo)) {
//if we still have something like (25555) remove it
//since we already set it to max, otherwise add collate or other info
if(originalExtraInfo.lastIndexOf(")") < (originalExtraInfo.length() - 1)) {
type.addAdditionalInformation(originalExtraInfo.substring(originalExtraInfo.lastIndexOf(")") + 1));
}
}
return type;
}
if (originalDefinition.toLowerCase(Locale.US).startsWith("ntext")
Expand All @@ -78,8 +90,14 @@ public DatabaseDataType toDatabaseDataType(Database database) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("nvarchar"));
// If there is additional specification after ntext (e.g. COLLATE), import that.
String originalExtraInfo = originalDefinition.replaceFirst("^(?i)\\[?ntext\\]?\\s*", "");
type.addAdditionalInformation("(max)"
+ (StringUtil.isEmpty(originalExtraInfo) ? "" : " " + originalExtraInfo));
type.addAdditionalInformation("(max)");
if(!StringUtil.isEmpty(originalExtraInfo)) {
//if we still have something like (25555) remove it
//since we already set it to max, otherwise add collate or other info
if(originalExtraInfo.lastIndexOf(")") < (originalExtraInfo.length() - 1)) {
type.addAdditionalInformation(originalExtraInfo.substring(originalExtraInfo.lastIndexOf(")") + 1));
}
}
return type;
}
if ("nclob".equals(originalDefinition.toLowerCase(Locale.US))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class DecimalType extends LiquibaseDataType {

private boolean autoIncrement;

@Override
public boolean isAutoIncrement() {
return autoIncrement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class IntType extends LiquibaseDataType {

private boolean autoIncrement;

@Override
public boolean isAutoIncrement() {
return autoIncrement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MediumIntType extends LiquibaseDataType {

private boolean autoIncrement;

@Override
public boolean isAutoIncrement() {
return autoIncrement;
}
Expand Down

0 comments on commit c1da538

Please sign in to comment.