mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:07:02 +00:00
refactor/changed the length of UserAttribute.name field
This commit is contained in:
parent
bf403d2772
commit
eed03ffab6
@ -95,6 +95,7 @@ object Migration extends MdcLoggable {
|
||||
dropConsentAuthContextDropIndex()
|
||||
alterMappedExpectedChallengeAnswerChallengeTypeLength()
|
||||
alterTransactionRequestChallengeChallengeTypeLength()
|
||||
alterUserAttributeNameLength()
|
||||
alterMappedCustomerAttribute(startedBeforeSchemifier)
|
||||
dropMappedBadLoginAttemptIndex()
|
||||
}
|
||||
@ -421,6 +422,13 @@ object Migration extends MdcLoggable {
|
||||
MigrationOfTransactionRequestChallengeChallengeTypeLength.alterColumnChallengeChallengeTypeLength(name)
|
||||
}
|
||||
}
|
||||
|
||||
private def alterUserAttributeNameLength(): Boolean = {
|
||||
val name = nameOf(alterUserAttributeNameLength)
|
||||
runOnce(name) {
|
||||
MigrationOfUserAttributeNameFieldLength.alterNameLength(name)
|
||||
}
|
||||
}
|
||||
private def alterMappedCustomerAttribute(startedBeforeSchemifier: Boolean): Boolean = {
|
||||
if(startedBeforeSchemifier == true) {
|
||||
logger.warn(s"Migration.database.alterMappedCustomerAttribute(true) cannot be run before Schemifier.")
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
package code.api.util.migration
|
||||
|
||||
import code.api.util.APIUtil
|
||||
import code.api.util.migration.Migration.{DbFunction, saveLog}
|
||||
import code.users.UserAttribute
|
||||
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 MigrationOfUserAttributeNameFieldLength {
|
||||
|
||||
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 alterNameLength(name: String): Boolean = {
|
||||
DbFunction.tableExists(UserAttribute, (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 UserAttribute ALTER COLUMN name varchar(255);
|
||||
|""".stripMargin
|
||||
case _ =>
|
||||
() =>
|
||||
"""
|
||||
|ALTER TABLE UserAttribute ALTER COLUMN name type varchar(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"""${UserAttribute._dbTableNameLC} table does not exist""".stripMargin
|
||||
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
|
||||
isSuccessful
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,7 @@ class UserAttribute extends UserAttributeTrait with LongKeyedMapper[UserAttribut
|
||||
override def getSingleton = UserAttribute
|
||||
object UserAttributeId extends MappedUUID(this)
|
||||
object UserId extends MappedUUID(this)
|
||||
object Name extends MappedString(this, 50)
|
||||
object Name extends MappedString(this, 255)
|
||||
object Type extends MappedString(this, 50)
|
||||
object `Value` extends MappedString(this, 255)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user