4910-dm-migration-error-for-oracle-19c (#4916)

* Remove all_constraints references which break in oracle 19c

* Add changelog

---------

Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
This commit is contained in:
jmarchionatto 2023-05-18 16:10:31 -04:00 committed by GitHub
parent c45809c8ee
commit 4482622602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 4910
title: "Remove some references to `all_constraints` table in oracle database migration tasks which were causing errors for version 19c."

View File

@ -160,11 +160,9 @@ public class DropIndexTask extends BaseTableTask {
@Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?";
findAndDropConstraint(findConstraintSql, dropConstraintSql);
} else if (getDriverType() == DriverTypeEnum.ORACLE_12C) {
@Language("SQL") String findConstraintSql = "SELECT DISTINCT constraint_name FROM user_cons_columns WHERE constraint_name = ? AND table_name = ?";
@Language("SQL") String findConstraintSql = "SELECT constraint_name FROM user_constraints WHERE constraint_name = ? AND table_name = ?";
@Language("SQL") String dropConstraintSql = "ALTER TABLE " + getTableName() + " DROP CONSTRAINT ?";
findAndDropConstraint(findConstraintSql, dropConstraintSql);
findConstraintSql = "SELECT DISTINCT constraint_name FROM all_constraints WHERE index_name = ? AND table_name = ?";
findAndDropConstraint(findConstraintSql, dropConstraintSql);
} else if (getDriverType() == DriverTypeEnum.MSSQL_2012) {
// Legacy deletion for SQL Server unique indexes
@Language("SQL") String findConstraintSql = "SELECT tc.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc WHERE tc.CONSTRAINT_NAME = ? AND tc.TABLE_NAME = ?";

View File

@ -164,10 +164,10 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask {
case ORACLE_12C:
@Language("SQL") String findNullableConstraintSql =
"SELECT acc.owner, acc.table_name, acc.column_name, search_condition_vc " +
"FROM all_cons_columns acc, all_constraints ac " +
"WHERE acc.constraint_name = ac.constraint_name " +
"AND acc.table_name = ac.table_name " +
"AND ac.constraint_type = ? " +
"FROM all_cons_columns acc, user_constraints uc " +
"WHERE acc.constraint_name = uc.constraint_name " +
"AND acc.table_name = uc.table_name " +
"AND uc.constraint_type = ? " +
"AND acc.table_name = ? " +
"AND acc.column_name = ? " +
"AND search_condition_vc = ? ";
@ -176,9 +176,8 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask {
params[1] = tableName.toUpperCase();
params[2] = columnName.toUpperCase();
params[3] = "\"" + columnName.toUpperCase() + "\" IS NOT NULL";
List<Map<String, Object>> queryResults = getConnectionProperties().getTxTemplate().execute(t -> {
return getConnectionProperties().newJdbcTemplate().query(findNullableConstraintSql, params, new ColumnMapRowMapper());
});
List<Map<String, Object>> queryResults = getConnectionProperties().getTxTemplate().execute(t ->
getConnectionProperties().newJdbcTemplate().query(findNullableConstraintSql, params, new ColumnMapRowMapper()));
// If this query returns a row then the existence of that row indicates that a NOT NULL constraint exists
// on this Column and we must override whatever result was previously calculated and set it to false
if (queryResults != null && queryResults.size() > 0 && queryResults.get(0) != null && !queryResults.get(0).isEmpty()) {