From 980914a73e19815b4da217c2b7fb67cb350de194 Mon Sep 17 00:00:00 2001 From: hongwei Date: Thu, 2 May 2024 16:48:59 +0200 Subject: [PATCH 1/7] refactor/Boot.scala improve logging --- .../src/main/scala/bootstrap/liftweb/Boot.scala | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index 06e882cd20..13a075800f 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -285,18 +285,6 @@ class Boot extends MdcLoggable { Views.views.vend.getOrCreateSystemView(SYSTEM_FIREHOSE_VIEW_ID).isDefined else Empty.isDefined - val comment: String = - s""" - |System view ${SYSTEM_OWNER_VIEW_ID} exists/created at the instance: ${owner} - |System view ${SYSTEM_AUDITOR_VIEW_ID} exists/created at the instance: ${auditor} - |System view ${SYSTEM_ACCOUNTANT_VIEW_ID} exists/created at the instance: ${accountant} - |System view ${SYSTEM_FIREHOSE_VIEW_ID} exists/created at the instance: ${accountFirehose} - |System view ${SYSTEM_STANDARD_VIEW_ID} exists/created at the instance: ${standard} - |System view ${SYSTEM_STAGE_ONE_VIEW_ID} exists/created at the instance: ${stageOne} - |System view ${SYSTEM_MANAGE_CUSTOM_VIEWS_VIEW_ID} exists/created at the instance: ${manageCustomViews} - |""".stripMargin - logger.info(comment) - APIUtil.getPropsValue("additional_system_views") match { case Full(value) => val viewSetUKOpenBanking = value.split(",").map(_.trim).toList @@ -313,8 +301,6 @@ class Boot extends MdcLoggable { if viewsUKOpenBanking.exists(_ == systemView) } { Views.views.vend.getOrCreateSystemView(systemView) - val comment = s"System view ${systemView} exists/created at the instance" - logger.info(comment) } case _ => // Do nothing } From 3bee92b409315872f13c0ea61d341f45f7aa649b Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 7 May 2024 14:24:33 +0200 Subject: [PATCH 2/7] refactor/revert the migration function back --- .../main/scala/bootstrap/liftweb/Boot.scala | 22 ++-- .../code/api/util/migration/Migration.scala | 10 +- .../MigrationInfoOfAccoutHolders.scala | 2 +- .../migration/MigrationOfAccountAccess.scala | 2 +- ...rationOfAccountAccessAddedConsumerId.scala | 2 +- .../MigrationOfAccountRoutings.scala | 2 +- .../util/migration/MigrationOfAuthUser.scala | 4 +- ...grationOfConsentAuthContextDropIndex.scala | 2 +- .../util/migration/MigrationOfConsumer.scala | 4 +- .../MigrationOfConsumerRateLimiting.scala | 2 +- .../MigrationOfCustomerAttributes.scala | 4 +- ...rationOfFastFireHoseMaterializedView.scala | 2 +- .../MigrationOfFastFireHoseView.scala | 2 +- ...tionOfMappedBadLoginAttemptDropIndex.scala | 2 +- .../migration/MigrationOfMappedConsent.scala | 6 +- ...edExpectedChallengeAnswerFieldLength.scala | 2 +- .../MigrationOfMappedUserAuthContext.scala | 2 +- ...grationOfMappedUserAuthContextUpdate.scala | 2 +- .../migration/MigrationOfMetricTable.scala | 2 +- .../MigrationOfOpnIDConnectToken.scala | 4 +- .../MigrationOfProductAttribute.scala | 2 +- .../migration/MigrationOfProductFee.scala | 2 +- .../migration/MigrationOfResourceUser.scala | 4 +- .../MigrationOfResourceUserIsDeleted.scala | 101 ++++++++++++++++++ .../MigrationOfSystemViewsToCustomViews.scala | 2 +- .../MigrationOfTransactionRequerst.scala | 2 +- ...nRequestChallengeChallengeTypeLength.scala | 2 +- ...rationOfUserAttributeNameFieldLength.scala | 2 +- ...igrationOfUserAuthContextFieldLength.scala | 2 +- .../migration/MigrationOfViewDefinition.scala | 2 +- ...MigrationOfViewDefinitionPermissions.scala | 2 +- .../MigrationOfWebhookUrlFieldLength.scala | 6 +- 32 files changed, 156 insertions(+), 53 deletions(-) create mode 100644 obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index 13a075800f..c4cebdb7ed 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -144,7 +144,7 @@ import net.liftweb.http.LiftRules.DispatchPF import net.liftweb.http._ import net.liftweb.http.provider.HTTPCookie import net.liftweb.json.Extraction -import net.liftweb.mapper._ +import net.liftweb.mapper.{DefaultConnectionIdentifier=>_, _} import net.liftweb.sitemap.Loc._ import net.liftweb.sitemap._ import net.liftweb.util.Helpers._ @@ -257,20 +257,20 @@ class Boot extends MdcLoggable { logger.info("Mapper database info: " + Migration.DbFunction.mapperDatabaseInfo(APIUtil.vendor)) - // DbFunction.tableExists(ResourceUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { - // case true => // DB already exist - // // Migration Scripts are used to update the model of OBP-API DB to a latest version. - // // Please note that migration scripts are executed before Lift Mapper Schemifier - //// Migration.database.executeScripts(startedBeforeSchemifier = true) - // logger.info("The Mapper database already exits. The scripts are executed BEFORE Lift Mapper Schemifier.") - // case false => // DB is still not created. The scripts will be executed after Lift Mapper Schemifier - // logger.info("The Mapper database is still not created. The scripts are going to be executed AFTER Lift Mapper Schemifier.") - // } + DbFunction.tableExists(ResourceUser) match { + case true => // DB already exist + // Migration Scripts are used to update the model of OBP-API DB to a latest version. + // Please note that migration scripts are executed before Lift Mapper Schemifier + Migration.database.executeScripts(startedBeforeSchemifier = true) + logger.info("The Mapper database already exits. The scripts are executed BEFORE Lift Mapper Schemifier.") + case false => // DB is still not created. The scripts will be executed after Lift Mapper Schemifier + logger.info("The Mapper database is still not created. The scripts are going to be executed AFTER Lift Mapper Schemifier.") + } // Migration Scripts are used to update the model of OBP-API DB to a latest version. // Please note that migration scripts are executed after Lift Mapper Schemifier - //Migration.database.executeScripts(startedBeforeSchemifier = false) + Migration.database.executeScripts(startedBeforeSchemifier = false) if (APIUtil.getPropsAsBoolValue("create_system_views_at_boot", true)) { // Create system views 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 ef5bb8d3cf..e7ad7c60b0 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 @@ -2,7 +2,7 @@ package code.api.util.migration import bootstrap.liftweb.CustomDBVendor -import java.sql.{ResultSet, SQLException} +import java.sql.{Connection, ResultSet, SQLException} import java.text.SimpleDateFormat import java.util.Date import code.api.util.APIUtil.{getPropsAsBoolValue, getPropsValue} @@ -17,7 +17,7 @@ import code.util.Helper.MdcLoggable import com.github.dwickern.macros.NameOf.nameOf import com.zaxxer.hikari.pool.ProxyConnection import net.liftweb.mapper.Schemifier.getDefaultSchemaName -import net.liftweb.mapper.{BaseMetaMapper, DB, SuperConnection} +import net.liftweb.mapper.{BaseMetaMapper, DB, DefaultConnectionIdentifier, SuperConnection} import scala.collection.immutable import scala.collection.mutable.HashMap @@ -492,10 +492,12 @@ object Migration extends MdcLoggable { * This function is copied from the module "net.liftweb.mapper.Schemifier". * The purpose is to provide answer does a table exist at a database instance. * For instance migration scripts needs to differentiate update of an instance from build a new one from scratch. + * note: 07.05.2024 now. we get the connection from HikariDatasource.ds instead of Liftweb. */ - def tableExists (table: BaseMetaMapper, connection: SuperConnection, actualTableNames: HashMap[String, String] = new HashMap[String, String]()): Boolean = { + def tableExists (table: BaseMetaMapper, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head, actualTableNames: HashMap[String, String] = new HashMap[String, String]()): Boolean = { val md = connection.getMetaData - using(md.getTables(null, getDefaultSchemaName(connection), null, null)){ rs => + val schema = connection.getSchema + using(md.getTables(null, schema, null, null)){ rs => def hasTable(rs: ResultSet): Boolean = if (!rs.next) false else rs.getString(3) match { diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala index 01e98c1140..321f33bf87 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationInfoOfAccoutHolders.scala @@ -18,7 +18,7 @@ object BankAccountHoldersAndOwnerViewAccess { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def saveInfoBankAccountHoldersAndOwnerViewAccessInfo(name: String): Boolean = { - DbFunction.tableExists(MapperAccountHolders, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MapperAccountHolders) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala index 0aad03910d..34ebe8c32a 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccess.scala @@ -9,7 +9,7 @@ import net.liftweb.util.DefaultConnectionIdentifier object TableAccountAccess { def populate(name: String): Boolean = { - DbFunction.tableExists(ViewPrivileges, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewPrivileges) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala index 9c056190ec..7c09c05436 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala @@ -18,7 +18,7 @@ object MigrationOfAccountAccessAddedConsumerId { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def addAccountAccessConsumerId(name: String): Boolean = { - DbFunction.tableExists(AccountAccess, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(AccountAccess) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala index 070e076f1c..999f38119f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountRoutings.scala @@ -17,7 +17,7 @@ object MigrationOfAccountRoutings { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populate(name: String): Boolean = { - DbFunction.tableExists(BankAccountRouting, (DB.use(DefaultConnectionIdentifier) { conn => conn })) match { + DbFunction.tableExists(BankAccountRouting) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala index 90f61b1599..5d353fc776 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala @@ -17,7 +17,7 @@ object MigrationOfAuthUser { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnUsernameProviderEmailFirstnameAndLastname(name: String): Boolean = { - DbFunction.tableExists(AuthUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(AuthUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -70,7 +70,7 @@ object MigrationOfAuthUser { } def dropIndexAtColumnUsername(name: String): Boolean = { - DbFunction.tableExists(AuthUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(AuthUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala index 3a25f41d2d..f2860a659b 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala @@ -38,7 +38,7 @@ object MigrationOfConsentAuthContextDropIndex { } def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedConsentAuthContext, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsentAuthContext) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit 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 27e30d7bbd..47e7e2ff60 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 @@ -16,7 +16,7 @@ object MigrationOfConsumer { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populateNamAndAppType(name: String): Boolean = { - DbFunction.tableExists(Consumer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(Consumer) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -62,7 +62,7 @@ object MigrationOfConsumer { } } def populateAzpAndSub(name: String): Boolean = { - DbFunction.tableExists(Consumer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(Consumer) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala index 3bb5a9dff5..eacfb3c0b8 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumerRateLimiting.scala @@ -19,7 +19,7 @@ object TableRateLmiting { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populate(name: String): Boolean = { - DbFunction.tableExists(RateLimiting, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(RateLimiting) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala index 89fee0eb2f..491090c502 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala @@ -18,7 +18,7 @@ object MigrationOfCustomerAttributes { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnValue(name: String): Boolean = { - DbFunction.tableExists(MappedCustomerAttribute, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedCustomerAttribute) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -57,7 +57,7 @@ object MigrationOfCustomerAttributes { } } def populateAzpAndSub(name: String): Boolean = { - DbFunction.tableExists(Consumer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(Consumer) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala index 8184288b73..627e1f5d3f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala @@ -17,7 +17,7 @@ object MigrationOfFastFireHoseMaterializedView { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def addFastFireHoseMaterializedView(name: String): Boolean = { - DbFunction.tableExists(ProductFee, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ProductFee) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala index 90c97f55fb..8c19ddcd5b 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala @@ -16,7 +16,7 @@ object MigrationOfFastFireHoseView { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def addFastFireHoseView(name: String): Boolean = { - DbFunction.tableExists(ProductFee, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ProductFee) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala index 4f6ceb1f61..4a5379d40b 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala @@ -36,7 +36,7 @@ object MigrationOfMappedBadLoginAttemptDropIndex { } def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedBadLoginAttempt, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedBadLoginAttempt) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala index b2fa9c7b84..4793303255 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala @@ -17,7 +17,7 @@ object MigrationOfMappedConsent { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnJsonWebToken(name: String): Boolean = { - DbFunction.tableExists(MappedConsent, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsent) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -57,7 +57,7 @@ object MigrationOfMappedConsent { } def alterColumnChallenge(name: String): Boolean = { - DbFunction.tableExists(MappedConsent, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsent) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -103,7 +103,7 @@ object MigrationOfMappedConsent { } } def alterColumnStatus(name: String): Boolean = { - DbFunction.tableExists(MappedConsent, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedConsent) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala index e29e8881e3..de12d5974b 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala @@ -17,7 +17,7 @@ object MigrationOfMappedExpectedChallengeAnswerFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnLength(name: String): Boolean = { - DbFunction.tableExists(MappedExpectedChallengeAnswer, (DB.use(DefaultConnectionIdentifier){ conn => conn})) + DbFunction.tableExists(MappedExpectedChallengeAnswer) match { case true => val startDate = System.currentTimeMillis() diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala index 4aa75adc94..46a1ec0d5e 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala @@ -17,7 +17,7 @@ object MigrationOfMappedUserAuthContext { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedUserAuthContext, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedUserAuthContext) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala index d817828b48..379c217b37 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala @@ -17,7 +17,7 @@ object MigrationOfMappedUserAuthContextUpdate { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def dropUniqueIndex(name: String): Boolean = { - DbFunction.tableExists(MappedUserAuthContextUpdate, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedUserAuthContextUpdate) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala index e2985093a1..a3536dfaf5 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala @@ -17,7 +17,7 @@ object MigrationOfMetricTable { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnCorrelationidLength(name: String): Boolean = { - DbFunction.tableExists(MappedMetric, (DB.use(DefaultConnectionIdentifier){ conn => conn})) + DbFunction.tableExists(MappedMetric) match { case true => val startDate = System.currentTimeMillis() diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala index 3c638c2588..f6b38ed177 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala @@ -17,7 +17,7 @@ object MigrationOfOpnIDConnectToken { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnAccessToken(name: String): Boolean = { - DbFunction.tableExists(OpenIDConnectToken, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(OpenIDConnectToken) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -56,7 +56,7 @@ object MigrationOfOpnIDConnectToken { } } def alterColumnRefreshToken(name: String): Boolean = { - DbFunction.tableExists(OpenIDConnectToken, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(OpenIDConnectToken) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala index a47576f108..94ad8fde24 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductAttribute.scala @@ -17,7 +17,7 @@ object MigrationOfProductAttribute { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populateTheFieldIsActive(name: String): Boolean = { - DbFunction.tableExists(MappedProductAttribute, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedProductAttribute) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala index bbd5890505..825e84e3d1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala @@ -16,7 +16,7 @@ object MigrationOfProductFee { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnProductFeeName(name: String): Boolean = { - DbFunction.tableExists(ProductFee, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ProductFee) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala index ab8cfe1764..6e7d186eb0 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala @@ -18,7 +18,7 @@ object MigrationOfResourceUser { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populateNewFieldIsDeleted(name: String): Boolean = { - DbFunction.tableExists(ResourceUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ResourceUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit @@ -56,7 +56,7 @@ object MigrationOfResourceUser { } def alterColumnEmail(name: String): Boolean = { - DbFunction.tableExists(ResourceUser, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ResourceUser) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala new file mode 100644 index 0000000000..7bea42d572 --- /dev/null +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala @@ -0,0 +1,101 @@ +package code.api.util.migration + +import code.api.util.APIUtil +import code.api.util.migration.Migration.{DbFunction, saveLog} +import code.model.Consumer +import code.model.dataAccess.ResourceUser +import net.liftweb.common.Full +import net.liftweb.mapper.{DB, Schemifier} +import net.liftweb.util.DefaultConnectionIdentifier + +import java.time.format.DateTimeFormatter +import java.time.{ZoneId, ZonedDateTime} + +object MigrationOfResourceUserIsDeleted { + + val oneDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1) + val oneYearInFuture = ZonedDateTime.now(ZoneId.of("UTC")).plusYears(1) + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") + + def populateNewFieldIsDeleted(name: String): Boolean = { + DbFunction.tableExists(ResourceUser) match { + case true => + val startDate = System.currentTimeMillis() + val commitId: String = APIUtil.gitCommit + var isSuccessful = false + + // Make back up + DbFunction.makeBackUpOfTable(ResourceUser) + + val emptyDeletedField = + for { + user <- ResourceUser.findAll() if user.isDeleted.getOrElse(false) == false + } yield { + user.IsDeleted(false).saveMe() + } + + val endDate = System.currentTimeMillis() + val comment: String = + s"""Updated number of rows: + |${emptyDeletedField.size} + |""".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 + } + } + + def alterColumnEmail(name: String): Boolean = { + DbFunction.tableExists(ResourceUser) 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") => + () => + """ALTER TABLE resourceuser ALTER COLUMN email varchar(100); + |""".stripMargin + case _ => + () => + """ALTER TABLE resourceuser ALTER COLUMN email type varchar(100); + |""".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"""${ResourceUser._dbTableNameLC} table does not exist""".stripMargin + saveLog(name, commitId, isSuccessful, startDate, endDate, comment) + isSuccessful + } + } + +} diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala index a4252eb699..a3daf1897f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfSystemViewsToCustomViews.scala @@ -16,7 +16,7 @@ object UpdateTableViewDefinition { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def populate(name: String): Boolean = { - DbFunction.tableExists(ViewDefinition, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewDefinition) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala index 405f510940..04e2e01ed7 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala @@ -17,7 +17,7 @@ object MigrationOfTransactionRequerst { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnDetails(name: String): Boolean = { - DbFunction.tableExists(MappedTransactionRequest, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedTransactionRequest) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala index 62ef7dbb39..f7b07ea6c6 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala @@ -17,7 +17,7 @@ object MigrationOfTransactionRequestChallengeChallengeTypeLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnChallengeChallengeTypeLength(name: String): Boolean = { - DbFunction.tableExists(MappedTransactionRequest, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedTransactionRequest) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala index 7a8f0e3bc1..66d633e5b9 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala @@ -17,7 +17,7 @@ object MigrationOfUserAttributeNameFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterNameLength(name: String): Boolean = { - DbFunction.tableExists(UserAttribute, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(UserAttribute) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala index d38aa41a1d..447feefeda 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala @@ -16,7 +16,7 @@ object MigrationOfUserAuthContextFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnKeyAndValueLength(name: String): Boolean = { - DbFunction.tableExists(MappedUserAuthContext, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(MappedUserAuthContext) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala index 64f9b01d28..6771437630 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinition.scala @@ -9,7 +9,7 @@ import net.liftweb.util.DefaultConnectionIdentifier object TableViewDefinition { def populate(name: String): Boolean = { - DbFunction.tableExists(ViewImpl, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewImpl) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala index 5711385c86..b7d8e7e230 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala @@ -9,7 +9,7 @@ import net.liftweb.util.DefaultConnectionIdentifier object MigrationOfViewDefinitionPermissions { def populate(name: String): Boolean = { - DbFunction.tableExists(ViewDefinition, (DB.use(DefaultConnectionIdentifier){ conn => conn})) match { + DbFunction.tableExists(ViewDefinition) match { case true => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala index 77b6f2c1ce..be6e65378b 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala @@ -18,9 +18,9 @@ object MigrationOfWebhookUrlFieldLength { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'") def alterColumnUrlLength(name: String): Boolean = { - DbFunction.tableExists(SystemAccountNotificationWebhook, (DB.use(DefaultConnectionIdentifier){ conn => conn})) && - DbFunction.tableExists(BankAccountNotificationWebhook, (DB.use(DefaultConnectionIdentifier){ conn => conn}))&& - DbFunction.tableExists(MappedAccountWebhook, (DB.use(DefaultConnectionIdentifier){ conn => conn})) + DbFunction.tableExists(SystemAccountNotificationWebhook) && + DbFunction.tableExists(BankAccountNotificationWebhook)&& + DbFunction.tableExists(MappedAccountWebhook) match { case true => val startDate = System.currentTimeMillis() From 11b4f9069cdcbca5c44322499efff4cdba73578e Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 7 May 2024 17:31:03 +0200 Subject: [PATCH 3/7] refactor/revert the migration function back - step2 --- .../src/main/scala/code/api/util/migration/Migration.scala | 7 ++++--- .../MigrationOfAccountAccessAddedConsumerId.scala | 2 +- .../code/api/util/migration/MigrationOfAuthUser.scala | 4 ++-- .../migration/MigrationOfConsentAuthContextDropIndex.scala | 2 +- .../api/util/migration/MigrationOfCustomerAttributes.scala | 2 +- .../MigrationOfFastFireHoseMaterializedView.scala | 2 +- .../api/util/migration/MigrationOfFastFireHoseView.scala | 2 +- .../MigrationOfMappedBadLoginAttemptDropIndex.scala | 2 +- .../code/api/util/migration/MigrationOfMappedConsent.scala | 6 +++--- ...grationOfMappedExpectedChallengeAnswerFieldLength.scala | 2 +- .../util/migration/MigrationOfMappedUserAuthContext.scala | 2 +- .../migration/MigrationOfMappedUserAuthContextUpdate.scala | 2 +- .../code/api/util/migration/MigrationOfMetricTable.scala | 2 +- .../api/util/migration/MigrationOfOpnIDConnectToken.scala | 4 ++-- .../code/api/util/migration/MigrationOfProductFee.scala | 2 +- .../code/api/util/migration/MigrationOfResourceUser.scala | 2 +- .../util/migration/MigrationOfResourceUserIsDeleted.scala | 2 +- .../util/migration/MigrationOfTransactionRequerst.scala | 2 +- ...nOfTransactionRequestChallengeChallengeTypeLength.scala | 2 +- .../MigrationOfUserAttributeNameFieldLength.scala | 2 +- .../migration/MigrationOfUserAuthContextFieldLength.scala | 2 +- .../util/migration/MigrationOfWebhookUrlFieldLength.scala | 2 +- .../storedprocedure/StoredProcedureUtils.scala | 6 +++--- 23 files changed, 32 insertions(+), 31 deletions(-) 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 e7ad7c60b0..6e50d8c085 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 @@ -511,9 +511,10 @@ object Migration extends MdcLoggable { /** * The purpose is to provide answer does a procedure exist at a database instance. */ - def procedureExists(name: String, connection: SuperConnection): Boolean = { + def procedureExists(name: String, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head): Boolean = { val md = connection.getMetaData - using(md.getProcedures(null, getDefaultSchemaName(connection), null)){ rs => + val schema = connection.getSchema + using(md.getProcedures(null, schema, null)){ rs => def hasProcedure(rs: ResultSet): Boolean = if (!rs.next) false else rs.getString(3) match { @@ -557,7 +558,7 @@ object Migration extends MdcLoggable { * * @return SQL command. */ - def maybeWrite(performWrite: Boolean, logFunc: (=> AnyRef) => Unit, connection: SuperConnection) (makeSql: () => String) : String ={ + def maybeWrite(performWrite: Boolean, logFunc: (=> AnyRef) => Unit, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head) (makeSql: () => String) : String ={ val ct = makeSql() logger.trace("maybeWrite DDL: "+ct) if (performWrite) { diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala index 7c09c05436..71b97a164c 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAccountAccessAddedConsumerId.scala @@ -25,7 +25,7 @@ object MigrationOfAccountAccessAddedConsumerId { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala index 5d353fc776..c1733fbe5f 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfAuthUser.scala @@ -24,7 +24,7 @@ object MigrationOfAuthUser { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => @@ -77,7 +77,7 @@ object MigrationOfAuthUser { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case _ => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala index f2860a659b..1f105ae6a0 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfConsentAuthContextDropIndex.scala @@ -45,7 +45,7 @@ object MigrationOfConsentAuthContextDropIndex { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case _ => () => "DROP INDEX IF EXISTS consentauthcontext_consentid_key_c;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala index 491090c502..908ffde0f1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfCustomerAttributes.scala @@ -25,7 +25,7 @@ object MigrationOfCustomerAttributes { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedcustomerattribute ALTER COLUMN mvalue varchar(2000);" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala index 627e1f5d3f..d923dff7a7 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseMaterializedView.scala @@ -75,7 +75,7 @@ object MigrationOfFastFireHoseMaterializedView { | ON (mappedbankaccount.bank = mapperaccountholders.accountbankpermalink and mappedbankaccount.theaccountid = mapperaccountholders.accountpermalink); |""".stripMargin val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") openOr("org.h2.Driver") match { case value if value.contains("org.h2.Driver") => () => migrationSql(false)//Note: H2 database, do not support the MATERIALIZED view diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala index 8c19ddcd5b..f949ddbe58 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfFastFireHoseView.scala @@ -23,7 +23,7 @@ object MigrationOfFastFireHoseView { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { () => """ |CREATE VIEW v_fast_firehose_accounts AS select diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala index 4a5379d40b..a3b124edaa 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedBadLoginAttemptDropIndex.scala @@ -43,7 +43,7 @@ object MigrationOfMappedBadLoginAttemptDropIndex { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case _ => () => "DROP INDEX IF EXISTS mappedbadloginattempt_musername;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala index 4793303255..97407ddfb1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedConsent.scala @@ -24,7 +24,7 @@ object MigrationOfMappedConsent { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedconsent ALTER COLUMN mjsonwebtoken text;" @@ -64,7 +64,7 @@ object MigrationOfMappedConsent { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => @@ -110,7 +110,7 @@ object MigrationOfMappedConsent { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala index de12d5974b..5cccde5eb9 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala @@ -25,7 +25,7 @@ object MigrationOfMappedExpectedChallengeAnswerFieldLength { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala index 46a1ec0d5e..4ba5df22ad 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContext.scala @@ -24,7 +24,7 @@ object MigrationOfMappedUserAuthContext { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "DROP INDEX IF EXISTS mappeduserauthcontext_muserid_mkey ON mappeduserauthcontext;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala index 379c217b37..c8756cdec1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedUserAuthContextUpdate.scala @@ -24,7 +24,7 @@ object MigrationOfMappedUserAuthContextUpdate { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "DROP INDEX IF EXISTS mappeduserauthcontextupdate_muserid_mkey ON mappeduserauthcontextupdate;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala index a3536dfaf5..8046960966 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMetricTable.scala @@ -25,7 +25,7 @@ object MigrationOfMetricTable { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala index f6b38ed177..a6bba3ff24 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfOpnIDConnectToken.scala @@ -24,7 +24,7 @@ object MigrationOfOpnIDConnectToken { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE openidconnecttoken ALTER COLUMN accesstoken text;" @@ -63,7 +63,7 @@ object MigrationOfOpnIDConnectToken { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE openidconnecttoken ALTER COLUMN refreshtoken text;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala index 825e84e3d1..f7484682e0 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfProductFee.scala @@ -23,7 +23,7 @@ object MigrationOfProductFee { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala index 6e7d186eb0..363d078b86 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUser.scala @@ -63,7 +63,7 @@ object MigrationOfResourceUser { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala index 7bea42d572..7d5fe428e6 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfResourceUserIsDeleted.scala @@ -63,7 +63,7 @@ object MigrationOfResourceUserIsDeleted { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala index 04e2e01ed7..1235728859 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequerst.scala @@ -24,7 +24,7 @@ object MigrationOfTransactionRequerst { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mdetails text;" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala index f7b07ea6c6..91cbc33e85 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala @@ -24,7 +24,7 @@ object MigrationOfTransactionRequestChallengeChallengeTypeLength { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType varchar(100);" diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala index 66d633e5b9..d646d61134 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAttributeNameFieldLength.scala @@ -24,7 +24,7 @@ object MigrationOfUserAttributeNameFieldLength { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala index 447feefeda..d0629fb4ee 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfUserAuthContextFieldLength.scala @@ -23,7 +23,7 @@ object MigrationOfUserAuthContextFieldLength { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala index be6e65378b..3ffa94a9b6 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfWebhookUrlFieldLength.scala @@ -28,7 +28,7 @@ object MigrationOfWebhookUrlFieldLength { var isSuccessful = false val executedSql = - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { APIUtil.getPropsValue("db.driver") match { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => diff --git a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala index 7669c4627a..7ca06811c7 100644 --- a/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala +++ b/obp-api/src/main/scala/code/bankconnectors/storedprocedure/StoredProcedureUtils.scala @@ -73,7 +73,7 @@ object StoredProcedureUtils extends MdcLoggable{ object StoredProceduresMockedData { def createOrDropMockedPostgresStoredProcedures() = { def create(): String = { - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { () => """CREATE OR REPLACE FUNCTION public.get_banks(p_out_bound_json text, INOUT in_bound_json text) | RETURNS text | LANGUAGE plpgsql @@ -113,13 +113,13 @@ object StoredProceduresMockedData { } } def drop(): String = { - DbFunction.maybeWrite(true, Schemifier.infoF _, DB.use(DefaultConnectionIdentifier){ conn => conn}) { + DbFunction.maybeWrite(true, Schemifier.infoF _) { () => "DROP FUNCTION public.get_banks(text, text);" } } val mapperDB = APIUtil.getPropsValue("stored_procedure_connector.driver") val connectorDB = APIUtil.getPropsValue("db.driver") - val thereIsTheProcedure = Migration.DbFunction.procedureExists("get_banks", DB.use(DefaultConnectionIdentifier){ conn => conn}) + val thereIsTheProcedure = Migration.DbFunction.procedureExists("get_banks") (mapperDB, connectorDB) match { case (Full(mapper), Full(connector)) if(mapper == connector && mapper == "org.postgresql.Driver" && thereIsTheProcedure) => drop() From 4025003e08607e5dae5532038d1556d16b6d3031 Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 8 May 2024 15:55:58 +0200 Subject: [PATCH 4/7] refactor/revert the migration function back - step3 --- .../migration/MigrationOfViewDefinitionPermissions.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala index b7d8e7e230..dd98763de1 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfViewDefinitionPermissions.scala @@ -34,7 +34,7 @@ object MigrationOfViewDefinitionPermissions { .canGrantAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .canRevokeAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .save - ).head + ) val standardView = ViewDefinition.find( NullRef(ViewDefinition.bank_id), @@ -57,10 +57,10 @@ object MigrationOfViewDefinitionPermissions { .canGrantAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .canRevokeAccessToViews_(ALL_SYSTEM_VIEWS_CREATED_FROM_BOOT.mkString(",")) .save - ).head + ) - val isSuccessful = ownerView && standardView + val isSuccessful = ownerView.isDefined && standardView.isDefined val endDate = System.currentTimeMillis() val comment: String = @@ -82,6 +82,7 @@ object MigrationOfViewDefinitionPermissions { """.stripMargin saveLog(name, commitId, isSuccessful, startDate, endDate, comment) isSuccessful + case false => val startDate = System.currentTimeMillis() val commitId: String = APIUtil.gitCommit From b2747f1a67f178be061b2f9f6909cb9d9feb9764 Mon Sep 17 00:00:00 2001 From: hongwei Date: Fri, 10 May 2024 10:24:27 +0200 Subject: [PATCH 5/7] refactor/revert the migration function back - step4 --- .../MigrationOfMappedExpectedChallengeAnswerFieldLength.scala | 4 ++-- ...tionOfTransactionRequestChallengeChallengeTypeLength.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala index 5cccde5eb9..ef5de1ecd7 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfMappedExpectedChallengeAnswerFieldLength.scala @@ -30,12 +30,12 @@ object MigrationOfMappedExpectedChallengeAnswerFieldLength { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => """ - |ALTER TABLE MappedExpectedChallengeAnswer ALTER COLUMN mChallengeType varchar(100); + |ALTER TABLE ExpectedChallengeAnswer ALTER COLUMN ChallengeType varchar(100); |""".stripMargin case _ => () => """ - |ALTER TABLE MappedExpectedChallengeAnswer ALTER COLUMN mChallengeType TYPE character varying(100); + |ALTER TABLE ExpectedChallengeAnswer ALTER COLUMN ChallengeType TYPE varchar(100); |""".stripMargin } } diff --git a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala index 91cbc33e85..4fbe1a1e5b 100644 --- a/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala +++ b/obp-api/src/main/scala/code/api/util/migration/MigrationOfTransactionRequestChallengeChallengeTypeLength.scala @@ -29,7 +29,7 @@ object MigrationOfTransactionRequestChallengeChallengeTypeLength { case Full(value) if value.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") => () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType varchar(100);" case _ => - () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType TYPE character varying(100);" + () => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType type varchar(100);" } } From 82802977327230644cbab5a58153023cb852ba70 Mon Sep 17 00:00:00 2001 From: hongwei Date: Fri, 10 May 2024 10:28:30 +0200 Subject: [PATCH 6/7] refactor/revert the migration function back - step5 --- .../code/api/util/migration/Migration.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 6e50d8c085..de0f55a55a 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 @@ -497,6 +497,11 @@ object Migration extends MdcLoggable { def tableExists (table: BaseMetaMapper, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head, actualTableNames: HashMap[String, String] = new HashMap[String, String]()): Boolean = { val md = connection.getMetaData val schema = connection.getSchema + try { + connection.asInstanceOf[ProxyConnection].close() + } catch { + case t: Throwable => logger.error(s"tableExists close connection, detail is: $t") + } using(md.getTables(null, schema, null, null)){ rs => def hasTable(rs: ResultSet): Boolean = if (!rs.next) false @@ -514,6 +519,12 @@ object Migration extends MdcLoggable { def procedureExists(name: String, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head): Boolean = { val md = connection.getMetaData val schema = connection.getSchema + try { + connection.asInstanceOf[ProxyConnection].close() + } catch { + case t: Throwable => logger.error(s"procedureExists close connection, detail is: $t") + } + using(md.getProcedures(null, schema, null)){ rs => def hasProcedure(rs: ResultSet): Boolean = if (!rs.next) false @@ -567,6 +578,11 @@ object Migration extends MdcLoggable { st.execute(ct) st.close } + try { + connection.asInstanceOf[ProxyConnection].close() + } catch { + case t: Throwable => logger.error(s"maybeWrite close connection, detail is: $t") + } ct } From a7ed850bb4f2408c99584e579734bd9da8a1a700 Mon Sep 17 00:00:00 2001 From: hongwei Date: Fri, 10 May 2024 10:49:09 +0200 Subject: [PATCH 7/7] refactor/revert the migration function back - step6 --- .../main/scala/bootstrap/liftweb/Boot.scala | 2 +- .../code/api/util/migration/Migration.scala | 108 ++++++++---------- .../scala/code/api/v4_0_0/APIMethods400.scala | 2 +- 3 files changed, 49 insertions(+), 63 deletions(-) diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index c4cebdb7ed..4e207267aa 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -255,7 +255,7 @@ class Boot extends MdcLoggable { schemifyAll() - logger.info("Mapper database info: " + Migration.DbFunction.mapperDatabaseInfo(APIUtil.vendor)) + logger.info("Mapper database info: " + Migration.DbFunction.mapperDatabaseInfo) DbFunction.tableExists(ResourceUser) match { case true => // DB already exist 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 de0f55a55a..ed5458dfb2 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 @@ -6,7 +6,6 @@ import java.sql.{Connection, ResultSet, SQLException} import java.text.SimpleDateFormat import java.util.Date import code.api.util.APIUtil.{getPropsAsBoolValue, getPropsValue} -import code.api.util.ErrorMessages.DatabaseConnectionClosedError import code.api.util.{APIUtil, ApiPropsWithAlias} import code.api.v4_0_0.DatabaseInfoJson import code.consumer.Consumers @@ -494,45 +493,41 @@ object Migration extends MdcLoggable { * For instance migration scripts needs to differentiate update of an instance from build a new one from scratch. * note: 07.05.2024 now. we get the connection from HikariDatasource.ds instead of Liftweb. */ - def tableExists (table: BaseMetaMapper, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head, actualTableNames: HashMap[String, String] = new HashMap[String, String]()): Boolean = { - val md = connection.getMetaData - val schema = connection.getSchema - try { - connection.asInstanceOf[ProxyConnection].close() - } catch { - case t: Throwable => logger.error(s"tableExists close connection, detail is: $t") - } - using(md.getTables(null, schema, null, null)){ rs => - def hasTable(rs: ResultSet): Boolean = - if (!rs.next) false - else rs.getString(3) match { - case s if s.toLowerCase == table._dbTableNameLC.toLowerCase => actualTableNames(table._dbTableNameLC) = s; true - case _ => hasTable(rs) + def tableExists (table: BaseMetaMapper, actualTableNames: HashMap[String, String] = new HashMap[String, String]()): Boolean = { + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val md = conn.getMetaData + val schema = getDefaultSchemaName(conn) + + using(md.getTables(null, schema, null, null)){ rs => + def hasTable(rs: ResultSet): Boolean = + if (!rs.next) false + else rs.getString(3) match { + case s if s.toLowerCase == table._dbTableNameLC.toLowerCase => actualTableNames(table._dbTableNameLC) = s; true + case _ => hasTable(rs) + } + + hasTable(rs) } - - hasTable(rs) } } /** * The purpose is to provide answer does a procedure exist at a database instance. */ - def procedureExists(name: String, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head): Boolean = { - val md = connection.getMetaData - val schema = connection.getSchema - try { - connection.asInstanceOf[ProxyConnection].close() - } catch { - case t: Throwable => logger.error(s"procedureExists close connection, detail is: $t") - } - - using(md.getProcedures(null, schema, null)){ rs => - def hasProcedure(rs: ResultSet): Boolean = - if (!rs.next) false - else rs.getString(3) match { - case s if s.toLowerCase == name => true - case _ => hasProcedure(rs) + def procedureExists(name: String): Boolean = { + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val md = conn.getMetaData + val schema = getDefaultSchemaName(conn) + using(md.getProcedures(null, schema, null)){ rs => + def hasProcedure(rs: ResultSet): Boolean = + if (!rs.next) false + else rs.getString(3) match { + case s if s.toLowerCase == name => true + case _ => hasProcedure(rs) + } + hasProcedure(rs) } - hasProcedure(rs) } } @@ -540,21 +535,14 @@ object Migration extends MdcLoggable { /** * The purpose is to provide info about the database in mapper mode. */ - def mapperDatabaseInfo(vendor: CustomDBVendor): DatabaseInfoJson = { - val connection = vendor.createOne.openOrThrowException(DatabaseConnectionClosedError) - try { - val md = connection.getMetaData - val productName = md.getDatabaseProductName() - val productVersion = md.getDatabaseProductVersion() - DatabaseInfoJson(product_name = productName, product_version = productVersion) - } finally { - try { - connection.asInstanceOf[ProxyConnection].close() - } catch { - case t: Throwable => logger.error(s"mapperDatabaseInfo.close connection throw exception, detail is: $t") - } + def mapperDatabaseInfo: DatabaseInfoJson = { + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val md = conn.getMetaData + val productName = md.getDatabaseProductName() + val productVersion = md.getDatabaseProductVersion() + DatabaseInfoJson(product_name = productName, product_version = productVersion) } - } /** @@ -569,21 +557,19 @@ object Migration extends MdcLoggable { * * @return SQL command. */ - def maybeWrite(performWrite: Boolean, logFunc: (=> AnyRef) => Unit, connection: Connection = APIUtil.vendor.newConnection(DefaultConnectionIdentifier).head) (makeSql: () => String) : String ={ - val ct = makeSql() - logger.trace("maybeWrite DDL: "+ct) - if (performWrite) { - logFunc(ct) - val st = connection.createStatement - st.execute(ct) - st.close - } - try { - connection.asInstanceOf[ProxyConnection].close() - } catch { - case t: Throwable => logger.error(s"maybeWrite close connection, detail is: $t") + def maybeWrite(performWrite: Boolean, logFunc: (=> AnyRef) => Unit) (makeSql: () => String) : String ={ + DB.use(net.liftweb.util.DefaultConnectionIdentifier) { + conn => + val ct = makeSql() + logger.trace("maybeWrite DDL: " + ct) + if (performWrite) { + logFunc(ct) + val st = conn.createStatement + st.execute(ct) + st.close + } + ct } - ct } /** diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index c91f0edbaa..da72ce71f1 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -151,7 +151,7 @@ trait APIMethods400 extends MdcLoggable { cc => implicit val ec = EndpointContext(Some(cc)) Future { - (Migration.DbFunction.mapperDatabaseInfo(APIUtil.vendor), HttpCode.`200`(cc.callContext)) + (Migration.DbFunction.mapperDatabaseInfo, HttpCode.`200`(cc.callContext)) } } }