Skip to content

Commit

Permalink
move synch to MigrationService exclusively
Browse files Browse the repository at this point in the history
  • Loading branch information
pbartusch committed Dec 17, 2021
1 parent 5fdcffa commit 7c36b18
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 2 additions & 0 deletions app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory,
val latestFromDockerHub = SmuiVersion.latestVersionFromDockerHub()
val current = SmuiVersion.parse(models.buildInfo.BuildInfo.version)

logger.info(s":: SMUI version of this instance: ($current)")

val versionInfo = (if (latestFromDockerHub.isEmpty || current.isEmpty) {
logger.error(s":: cannot determine version diff between latestFromDockerHub and current ($latestFromDockerHub, $current)")

Expand Down
11 changes: 0 additions & 11 deletions app/models/SearchManagementRepository.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package models

import java.io.FileInputStream
import java.time.LocalDateTime
import java.util.{Date, UUID}
import javax.inject.Inject
Expand All @@ -18,16 +17,6 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT

private val db = dbapi.database("default")


def syncPredefinedTagsWithDB(predefinedTagsFileName: Option[String]): Unit = {
db.withTransaction { implicit connection =>
for (fileName <- predefinedTagsFileName) {
val tags = PredefinedTag.fromStream(new FileInputStream(fileName))
PredefinedTag.updateInDB(tags)
}
}
}

/**
* List all Solr Indeces the SearchInput's can be configured for.
*/
Expand Down
34 changes: 22 additions & 12 deletions app/services/MigrationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import play.api.db.DBApi
import models.{DatabaseExecutionContext, SearchManagementRepository}
import models.FeatureToggleModel.FeatureToggleService
import models.eventhistory.InputEvent
import models.input.PredefinedTag
import play.api.db.evolutions.ApplicationEvolutions
import java.io.FileInputStream

@javax.inject.Singleton
class MigrationService @Inject()(dbapi: DBApi, toggleService: FeatureToggleService, searchManagementRepository: SearchManagementRepository, applicationEvolutions: ApplicationEvolutions)(implicit ec: DatabaseExecutionContext) extends Logging {
Expand Down Expand Up @@ -61,28 +63,36 @@ class MigrationService @Inject()(dbapi: DBApi, toggleService: FeatureToggleServi
}
}

private def syncPredefinedTagsWithDB() = {
db.withTransaction { implicit connection =>


if (toggleService.isRuleTaggingActive) {
// We can only sync rules if we are up to date on our evolutions.
if (evolutionsUpToDate) {
// On startup, always sync predefined tags with the DB
logger.info(("Database evolutions are up to date, now syncing any predefined tags"))
val tags = PredefinedTag.fromStream(new FileInputStream(toggleService.predefinedTagsFileName.get))
PredefinedTag.updateInDB(tags)
}
else {
logger.error("Database evolutions are not up to date, so not syncing any predefined tags with database")
}
}
}
}

// protect all migrations within a try-catch. In case, migrations fail, try to bootstrap SMUI anyway!!
// TODO Compile Time Dependency Injection & Play evolutions seem to be entangled unfavorably. Therefore, during development (DEV environment), it might be necessary to reload / restart the application (happened, when testing the migration towards v3.11.9).
try {

virtuallyCreateEventsPreVersion38()
syncPredefinedTagsWithDB()

} catch {
case e: Throwable => {
logger.error(s"In MigrationService :: exception during migration, e = ${e.toString}")
}
}


if (toggleService.isRuleTaggingActive) {
// We can only sync rules if we are up to date on our evolutions.
if (evolutionsUpToDate) {
// On startup, always sync predefined tags with the DB
logger.info(("Database evolutions are up to date, now syncing any predefined tags"))
searchManagementRepository.syncPredefinedTagsWithDB(toggleService.predefinedTagsFileName)
}
else {
logger.error("Database evolutions are not up to date, so not syncing any predefined tags with database")
}
}
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.typesafe.sbt.GitBranchPrompt

name := "search-management-ui"
version := "3.13.1"
version := "3.13.2"

scalaVersion := "2.12.11"

Expand Down

0 comments on commit 7c36b18

Please sign in to comment.