From be19acb7c3317f2c0f802889efa6d72047d80f65 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 12 Oct 2021 12:00:21 -0400 Subject: [PATCH] Fix Postgres migration --- ...gratePostgresTextClobToBinaryClobTask.java | 19 ++++++++++++------- .../fhir/jpa/migrate/tasks/api/Builder.java | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/MigratePostgresTextClobToBinaryClobTask.java b/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/MigratePostgresTextClobToBinaryClobTask.java index 1878eb261d1..612fcf99d50 100644 --- a/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/MigratePostgresTextClobToBinaryClobTask.java +++ b/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/MigratePostgresTextClobToBinaryClobTask.java @@ -26,6 +26,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.SQLException; +import java.util.Locale; public class MigratePostgresTextClobToBinaryClobTask extends BaseTableColumnTask { private static final Logger ourLog = LoggerFactory.getLogger(MigratePostgresTextClobToBinaryClobTask.class); @@ -49,18 +50,22 @@ public class MigratePostgresTextClobToBinaryClobTask extends BaseTableColumnTask return; } - JdbcUtils.ColumnType columnType = JdbcUtils.getColumnType(getConnectionProperties(), getTableName(), getColumnName()); + String tableName = getTableName(); + String columnName = getColumnName(); + JdbcUtils.ColumnType columnType = JdbcUtils.getColumnType(getConnectionProperties(), tableName, columnName); if (columnType.getColumnTypeEnum() == ColumnTypeEnum.LONG) { - ourLog.info("Table {} column {} is already of type LONG, no migration needed", getTableName(), getColumnName()); + ourLog.info("Table {} column {} is already of type LONG, no migration needed", tableName, columnName); return; } - String tempColumnName = getColumnName() + "_m"; + String tempColumnName = columnName + "_m".toLowerCase(); + tableName = tableName.toLowerCase(); + columnName = columnName.toLowerCase(); - executeSql(getTableName(), "alter table ? add column ? oid", getTableName(), tempColumnName); - executeSql(getTableName(), "update ? set ? = cast(? as oid) where ? is not null", getTableName(), tempColumnName, getColumnName(), getColumnName()); - executeSql(getTableName(), "alter table ? drop column ?", getTableName(), getColumnName()); - executeSql(getTableName(), "alter table ? rename column ? to ?", getTableName(), tempColumnName, getColumnName()); + executeSql(tableName, "alter table " + tableName + " add column " + tempColumnName + " oid"); + executeSql(tableName, "update " + tableName + " set " + tempColumnName + " = cast(" + columnName + " as oid) where " + columnName + " is not null"); + executeSql(tableName, "alter table " + tableName + " drop column " + columnName); + executeSql(tableName, "alter table " + tableName + " rename column " + tempColumnName + " to " + columnName); } } diff --git a/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java b/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java index 571a0d6eb37..06a5cdddce4 100644 --- a/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java +++ b/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java @@ -253,7 +253,7 @@ public class Builder { MigratePostgresTextClobToBinaryClobTask task = new MigratePostgresTextClobToBinaryClobTask(myRelease, theVersion); task.setTableName(getTableName()); task.setColumnName(theColumnName); - + addTask(task); } public class BuilderAddIndexWithName {