Skip to content

Commit 821ebf9

Browse files
authored
Merge pull request #2591 from constantine2nd/develop
Change type of Consumer.aud from char 250 to text
2 parents c475fde + a05648f commit 821ebf9

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎obp-api/src/main/scala/code/api/util/migration/Migration.scala‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ object Migration extends MdcLoggable {
100100
// populateViewDefinitionCanSeeTransactionStatus()
101101
alterCounterpartyLimitFieldType()
102102
populateMigrationOfViewPermissions(startedBeforeSchemifier)
103+
changeTypeOfAudFieldAtConsumerTable()
103104
}
104105

105106
private def dummyScript(): Boolean = {
@@ -254,6 +255,12 @@ object Migration extends MdcLoggable {
254255
MigrationOfConsumer.populateAzpAndSub(name)
255256
}
256257
}
258+
private def changeTypeOfAudFieldAtConsumerTable(): Boolean = {
259+
val name = nameOf(changeTypeOfAudFieldAtConsumerTable)
260+
runOnce(name) {
261+
MigrationOfConsumer.alterTypeofAud(name)
262+
}
263+
}
257264
private def alterTableMappedUserAuthContext(startedBeforeSchemifier: Boolean): Boolean = {
258265
if(startedBeforeSchemifier == true) {
259266
logger.warn(s"Migration.database.alterTableMappedUserAuthContext(true) cannot be run before Schemifier.")

‎obp-api/src/main/scala/code/api/util/migration/MigrationOfConsumer.scala‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package code.api.util.migration
22

33
import java.time.format.DateTimeFormatter
44
import java.time.{ZoneId, ZonedDateTime}
5-
65
import code.api.util.APIUtil
76
import code.api.util.migration.Migration.{DbFunction, saveLog}
87
import code.model.{AppType, Consumer}
9-
import net.liftweb.mapper.DB
8+
import net.liftweb.common.Full
9+
import net.liftweb.mapper.{DB, Schemifier}
1010
import net.liftweb.util.{DefaultConnectionIdentifier, Helpers}
1111

1212
object MigrationOfConsumer {
@@ -107,4 +107,52 @@ object MigrationOfConsumer {
107107
isSuccessful
108108
}
109109
}
110+
111+
112+
def alterTypeofAud(name: String): Boolean = {
113+
DbFunction.tableExists(Consumer) match {
114+
case true =>
115+
val startDate = System.currentTimeMillis()
116+
val commitId: String = APIUtil.gitCommit
117+
var isSuccessful = false
118+
119+
val executedSql =
120+
DbFunction.maybeWrite(true, Schemifier.infoF _) {
121+
APIUtil.getPropsValue("db.driver") match {
122+
case Full(dbDriver) if dbDriver.contains("com.microsoft.sqlserver.jdbc.SQLServerDriver") =>
123+
() =>
124+
"""
125+
|ALTER TABLE consumer ALTER COLUMN aud VARCHAR(MAX) NULL;
126+
|""".stripMargin
127+
case _ =>
128+
() =>
129+
"""
130+
|ALTER TABLE consumer ALTER COLUMN aud TYPE text;
131+
|""".stripMargin
132+
}
133+
134+
}
135+
136+
val endDate = System.currentTimeMillis()
137+
val comment: String =
138+
s"""Executed SQL:
139+
|$executedSql
140+
|""".stripMargin
141+
isSuccessful = true
142+
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
143+
isSuccessful
144+
145+
case false =>
146+
val startDate = System.currentTimeMillis()
147+
val commitId: String = APIUtil.gitCommit
148+
val isSuccessful = false
149+
val endDate = System.currentTimeMillis()
150+
val comment: String =
151+
s"""${Consumer._dbTableNameLC} table does not exist""".stripMargin
152+
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
153+
isSuccessful
154+
}
155+
}
156+
157+
110158
}

‎obp-api/src/main/scala/code/model/OAuth.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class Consumer extends LongKeyedMapper[Consumer] with CreatedUpdated{
541541
// because different databases treat unique indexes on NULL values differently.
542542
override def defaultValue = APIUtil.generateUUID()
543543
}
544-
object aud extends MappedString(this, 250) {
544+
object aud extends MappedText(this) {
545545
override def defaultValue = null
546546
}
547547
object iss extends MappedString(this, 250) {

0 commit comments

Comments
 (0)