From b3e4aebd3e368d1a1cbc1048c63883e9d4bd7c01 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 6 Dec 2022 00:19:46 +0100 Subject: [PATCH] refactor/added the MigrationOfAccountHolderAddedSource --- .../code/api/util/migration/Migration.scala | 7 +++ .../MigrationOfAccountHolderAddedSource.scala | 56 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountHolderAddedSource.scala 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 540a4448d..48e7274b6 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 @@ -61,6 +61,7 @@ object Migration extends MdcLoggable { def executeScripts(startedBeforeSchemifier: Boolean): Boolean = executeScript { dummyScript() + addMapperAccountHoldersFieldSource() addAccountAccessConsumerId() populateTableViewDefinition() populateTableAccountAccess() @@ -427,6 +428,12 @@ object Migration extends MdcLoggable { } } + private def addMapperAccountHoldersFieldSource(): Boolean = { + val name = nameOf(addMapperAccountHoldersFieldSource) + runOnce(name) { + MigrationOfAccountHolderAddedSource.addMapperAccountHoldersSource(name) + } + } } /** diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountHolderAddedSource.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountHolderAddedSource.scala new file mode 100644 index 000000000..98a2ee3ee --- /dev/null +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountHolderAddedSource.scala @@ -0,0 +1,56 @@ +package code.api.util.migration + +import code.api.util.APIUtil +import code.api.util.migration.Migration.{DbFunction, saveLog} +import code.accountholders.MapperAccountHolders +import net.liftweb.common.Full +import net.liftweb.mapper.{DB, Schemifier} +import net.liftweb.util.DefaultConnectionIdentifier + +object MigrationOfAccountHolderAddedSource { + + + def addMapperAccountHoldersSource(name: String): Boolean = { + DbFunction.tableExists(MapperAccountHolders, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + case true => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + var isSuccessful = false + + val executedSql = + DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + APIUtil.getPropsValue("db.driver") match { + case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => + () => + s""" + |ALTER TABLE mapperaccountholders ADD COLUMN IF NOT EXISTS "source" character varchar(255); + |""".stripMargin + case _ => + () => + s""" + |ALTER TABLE mapperaccountholders ADD COLUMN IF NOT EXISTS "source" character varying(255); + |""".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"""${MapperAccountHolders._dbTableNameLC} table does not exist""".stripMargin + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + } + } +} \ No newline at end of file