mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:47:01 +00:00
feature/Azure as the OpenID Connect Identity Provider - add migrtion scripts
This commit is contained in:
parent
76a8ce7723
commit
db8cfaa014
@ -82,6 +82,8 @@ object Migration extends MdcLoggable {
|
||||
deleteDuplicatedRowsInTheTableUserAuthContext()
|
||||
populateTheFieldDeletedAtResourceUser(startedBeforeSchemifier)
|
||||
populateTheFieldIsActiveAtProductAttribute(startedBeforeSchemifier)
|
||||
alterColumnUsernameProviderFirstnameAndLastnameAtAuthUser(startedBeforeSchemifier)
|
||||
alterColumnEmailAtResourceUser(startedBeforeSchemifier)
|
||||
}
|
||||
|
||||
private def dummyScript(): Boolean = {
|
||||
@ -259,6 +261,28 @@ object Migration extends MdcLoggable {
|
||||
}
|
||||
}
|
||||
}
|
||||
private def alterColumnUsernameProviderFirstnameAndLastnameAtAuthUser(startedBeforeSchemifier: Boolean): Boolean = {
|
||||
if(startedBeforeSchemifier == true) {
|
||||
logger.warn(s"Migration.database.alterColumnUsernameProviderFirstnameAndLastnameAtAuthUser(true) cannot be run before Schemifier.")
|
||||
true
|
||||
} else {
|
||||
val name = nameOf(alterColumnUsernameProviderFirstnameAndLastnameAtAuthUser(startedBeforeSchemifier))
|
||||
runOnce(name) {
|
||||
MigrationOfAuthUser.alterColumnUsernameProviderEmailFirstnameAndLastname(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
private def alterColumnEmailAtResourceUser(startedBeforeSchemifier: Boolean): Boolean = {
|
||||
if(startedBeforeSchemifier == true) {
|
||||
logger.warn(s"Migration.database.alterColumnEmailAtResourceUser(true) cannot be run before Schemifier.")
|
||||
true
|
||||
} else {
|
||||
val name = nameOf(alterColumnEmailAtResourceUser(startedBeforeSchemifier))
|
||||
runOnce(name) {
|
||||
MigrationOfResourceUser.alterColumnEmail(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
package code.api.util.migration
|
||||
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.{ZoneId, ZonedDateTime}
|
||||
|
||||
import code.api.util.APIUtil
|
||||
import code.api.util.migration.Migration.{DbFunction, saveLog}
|
||||
import code.model.dataAccess.AuthUser
|
||||
import net.liftweb.common.Full
|
||||
import net.liftweb.mapper.{DB, Schemifier}
|
||||
import net.liftweb.util.DefaultConnectionIdentifier
|
||||
|
||||
object MigrationOfAuthUser {
|
||||
|
||||
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 alterColumnUsernameProviderEmailFirstnameAndLastname(name: String): Boolean = {
|
||||
DbFunction.tableExists(AuthUser, (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 authuser ALTER COLUMN username varchar(100);
|
||||
|ALTER TABLE authuser ALTER COLUMN provider varchar(100);
|
||||
|ALTER TABLE authuser ALTER COLUMN firstname varchar(100);
|
||||
|ALTER TABLE authuser ALTER COLUMN lastname varchar(100);
|
||||
|ALTER TABLE authuser ALTER COLUMN email varchar(100);
|
||||
|""".stripMargin
|
||||
case _ =>
|
||||
() =>
|
||||
"""
|
||||
|ALTER TABLE authuser ALTER COLUMN username type varchar(100);
|
||||
|ALTER TABLE authuser ALTER COLUMN provider type varchar(100);
|
||||
|ALTER TABLE authuser ALTER COLUMN firstname type varchar(100);
|
||||
|ALTER TABLE authuser ALTER COLUMN lastname type varchar(100);
|
||||
|ALTER TABLE authuser 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"""${AuthUser._dbTableNameLC} table does not exist""".stripMargin
|
||||
saveLog(name, commitId, isSuccessful, startDate, endDate, comment)
|
||||
isSuccessful
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,10 +5,11 @@ import java.time.{ZoneId, ZonedDateTime}
|
||||
|
||||
import code.api.util.APIUtil
|
||||
import code.api.util.migration.Migration.{DbFunction, saveLog}
|
||||
import code.model.Consumer
|
||||
import code.model.dataAccess.ResourceUser
|
||||
import code.model.{AppType, Consumer}
|
||||
import net.liftweb.mapper.DB
|
||||
import net.liftweb.util.{DefaultConnectionIdentifier, Helpers}
|
||||
import net.liftweb.common.Full
|
||||
import net.liftweb.mapper.{DB, Schemifier}
|
||||
import net.liftweb.util.DefaultConnectionIdentifier
|
||||
|
||||
object MigrationOfResourceUser {
|
||||
|
||||
@ -53,4 +54,48 @@ object MigrationOfResourceUser {
|
||||
isSuccessful
|
||||
}
|
||||
}
|
||||
|
||||
def alterColumnEmail(name: String): Boolean = {
|
||||
DbFunction.tableExists(ResourceUser, (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 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ class AuthUser extends MegaProtoUser[AuthUser] with MdcLoggable {
|
||||
|
||||
override lazy val firstName = new MyFirstName
|
||||
|
||||
protected class MyFirstName extends MappedString(this, 32) {
|
||||
protected class MyFirstName extends MappedString(this, 100) {
|
||||
def isEmpty(msg: => String)(value: String): List[FieldError] =
|
||||
value match {
|
||||
case null => List(FieldError(this, Text(msg))) // issue 179
|
||||
@ -114,7 +114,7 @@ class AuthUser extends MegaProtoUser[AuthUser] with MdcLoggable {
|
||||
|
||||
override lazy val lastName = new MyLastName
|
||||
|
||||
protected class MyLastName extends MappedString(this, 32) {
|
||||
protected class MyLastName extends MappedString(this, 100) {
|
||||
def isEmpty(msg: => String)(value: String): List[FieldError] =
|
||||
value match {
|
||||
case null => List(FieldError(this, Text(msg))) // issue 179
|
||||
@ -160,7 +160,7 @@ class AuthUser extends MegaProtoUser[AuthUser] with MdcLoggable {
|
||||
* The username field for the User.
|
||||
*/
|
||||
lazy val username: userName = new userName()
|
||||
class userName extends MappedString(this, 64) {
|
||||
class userName extends MappedString(this, 100) {
|
||||
def isEmpty(msg: => String)(value: String): List[FieldError] =
|
||||
value match {
|
||||
case null => List(FieldError(this, Text(msg))) // issue 179
|
||||
@ -309,7 +309,7 @@ class AuthUser extends MegaProtoUser[AuthUser] with MdcLoggable {
|
||||
* The provider field for the User.
|
||||
*/
|
||||
lazy val provider: userProvider = new userProvider()
|
||||
class userProvider extends MappedString(this, 64) {
|
||||
class userProvider extends MappedString(this, 100) {
|
||||
override def displayName = S.?("provider")
|
||||
override val fieldId = Some(Text("txtProvider"))
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ class ResourceUser extends LongKeyedMapper[ResourceUser] with User with ManyToMa
|
||||
|
||||
object id extends MappedLongIndex(this)
|
||||
object userId_ extends MappedUUID(this)
|
||||
object email extends MappedEmail(this, 48){
|
||||
object email extends MappedEmail(this, 100){
|
||||
override def required_? = false
|
||||
}
|
||||
object name_ extends MappedString(this, 100){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user