Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
Marko Milić 2022-07-15 11:39:31 +02:00
commit f55c818daf
2 changed files with 65 additions and 0 deletions

View File

@ -94,6 +94,7 @@ object Migration extends MdcLoggable {
alterWebhookColumnUrlLength()
dropConsentAuthContextDropIndex()
alterMappedExpectedChallengeAnswerChallengeTypeLength()
alterTransactionRequestChallengeChallengeTypeLength()
}
private def dummyScript(): Boolean = {
@ -386,6 +387,13 @@ object Migration extends MdcLoggable {
}
}
private def alterTransactionRequestChallengeChallengeTypeLength(): Boolean = {
val name = nameOf(alterTransactionRequestChallengeChallengeTypeLength)
runOnce(name) {
MigrationOfTransactionRequestChallengeChallengeTypeLength.alterColumnChallengeChallengeTypeLength(name)
}
}
}
/**

View File

@ -0,0 +1,57 @@
package code.api.util.migration
import code.api.util.APIUtil
import code.api.util.migration.Migration.{DbFunction, saveLog}
import code.transactionrequests.MappedTransactionRequest
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 MigrationOfTransactionRequestChallengeChallengeTypeLength {
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 alterColumnChallengeChallengeTypeLength(name: String): Boolean = {
DbFunction.tableExists(MappedTransactionRequest, (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") =>
() => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType varchar(100);"
case _ =>
() => "ALTER TABLE mappedtransactionrequest ALTER COLUMN mChallenge_ChallengeType TYPE character varying(100);"
}
}
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"""${MappedTransactionRequest._dbTableNameLC} table does not exist""".stripMargin
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
isSuccessful
}
}
}