diff --git a/obp-api/src/main/scala/code/api/util/migration/Migration.scala b/obp-api/src/main/scala/code/api/util/migration/Migration.scala index 182f39a70..7da81d82c 100644 --- a/obp-api/src/main/scala/code/api/util/migration/Migration.scala +++ b/obp-api/src/main/scala/code/api/util/migration/Migration.scala @@ -100,6 +100,7 @@ object Migration extends MdcLoggable { // populateViewDefinitionCanSeeTransactionStatus() alterCounterpartyLimitFieldType() populateMigrationOfViewPermissions(startedBeforeSchemifier) + changeTypeOfAudFieldAtConsumerTable() } private def dummyScript(): Boolean = { @@ -254,6 +255,12 @@ object Migration extends MdcLoggable { MigrationOfConsumer.populateAzpAndSub(name) } } + private def changeTypeOfAudFieldAtConsumerTable(): Boolean = { + val name = nameOf(changeTypeOfAudFieldAtConsumerTable) + runOnce(name) { + MigrationOfConsumer.alterTypeofAud(name) + } + } private def alterTableMappedUserAuthContext(startedBeforeSchemifier: Boolean): Boolean = { if(startedBeforeSchemifier == true) { logger.warn(s"Migration.database.alterTableMappedUserAuthContext(true) cannot be run before Schemifier.") diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala index 47e7e2ff6..1bd25bd2f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala @@ -2,11 +2,11 @@ package code.api.util.migration import java.time.format.DateTimeFormatter import java.time.{ZoneId, ZonedDateTime} - import code.api.util.APIUtil import code.api.util.migration.Migration.{DbFunction, saveLog} import code.model.{AppType, Consumer} -import net.liftweb.mapper.DB +import net.liftweb.common.Full +import net.liftweb.mapper.{DB, Schemifier} import net.liftweb.util.{DefaultConnectionIdentifier, Helpers} object MigrationOfConsumer { @@ -107,4 +107,52 @@ object MigrationOfConsumer { isSuccessful } } + + + def alterTypeofAud(name: String): Boolean = { + DbFunction.tableExists(Consumer) match { + case true => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + var isSuccessful = false + + val executedSql = + DbFunction.maybeWrite(true, Schemifier.infoF _) { + APIUtil.getPropsValue("db.driver") match { + case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + () => + """ + |ALTER TABLE consumer ALTER COLUMN aud VARCHAR(MAX) NULL; + |""".stripMargin + case _ => + () => + """ + |ALTER TABLE consumer ALTER COLUMN aud TYPE text; + |""".stripMargin + } + + } + + val endDate = System.currentTimeMillis() + val comment: String = + s"""Executed SQL: + |$executedSql + |""".stripMargin + isSuccessful = true + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + + case false => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + val isSuccessful = false + val endDate = System.currentTimeMillis() + val comment: String = + s"""${Consumer._dbTableNameLC} table does not exist""".stripMargin + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + } + } + + } diff --git a/obp-api/src/main/scala/code/model/OAuth.scala b/obp-api/src/main/scala/code/model/OAuth.scala index bf23e5719..f5b1b8c65 100644 --- a/obp-api/src/main/scala/code/model/OAuth.scala +++ b/obp-api/src/main/scala/code/model/OAuth.scala @@ -541,7 +541,7 @@ class Consumer extends LongKeyedMapper[Consumer] with CreatedUpdated{ // because different databases treat unique indexes on NULL values differently. override def defaultValue = APIUtil.generateUUID() } - object aud extends MappedString(this, 250) { + object aud extends MappedText(this) { override def defaultValue = null } object iss extends MappedString(this, 250) {