Skip to content

Commit

Permalink
#2335 Fix schema initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 7, 2022
1 parent f3be6bd commit c0c2442
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ScalliGraph
31 changes: 18 additions & 13 deletions migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,25 @@ class Output @Inject() (

override def startMigration(): Try[Unit] = {
implicit val authContext: AuthContext = LocalUserSrv.getSystemAuthContext
if (resumeMigration) {
if (resumeMigration)
db.addSchemaIndexes(theHiveSchema)
.flatMap(_ => db.addSchemaIndexes(cortexSchema))
db.roTransaction { implicit graph =>
profiles ++= profileSrv.startTraversal.toSeq.map(p => p.name -> p)
organisations ++= organisationSrv.startTraversal.toSeq.map(o => o.name -> o)
users ++= userSrv.startTraversal.toSeq.map(u => u.name -> u)
impactStatuses ++= impactStatusSrv.startTraversal.toSeq.map(s => s.value -> s)
resolutionStatuses ++= resolutionStatusSrv.startTraversal.toSeq.map(s => s.value -> s)
observableTypes ++= observableTypeSrv.startTraversal.toSeq.map(o => o.name -> o)
customFields ++= customFieldSrv.startTraversal.toSeq.map(c => c.name -> c)
caseTemplates ++= caseTemplateSrv.startTraversal.toSeq.map(c => c.name -> c)
}
Success(())
} else
.flatMap { _ =>
db.roTransaction { implicit graph =>
profiles ++= profileSrv.startTraversal.toSeq.map(p => p.name -> p)
organisations ++= organisationSrv.startTraversal.toSeq.map(o => o.name -> o)
users ++= userSrv.startTraversal.toSeq.map(u => u.name -> u)
impactStatuses ++= impactStatusSrv.startTraversal.toSeq.map(s => s.value -> s)
resolutionStatuses ++= resolutionStatusSrv.startTraversal.toSeq.map(s => s.value -> s)
observableTypes ++= observableTypeSrv.startTraversal.toSeq.map(o => o.name -> o)
customFields ++= customFieldSrv.startTraversal.toSeq.map(c => c.name -> c)
caseTemplates ++= caseTemplateSrv.startTraversal.toSeq.map(c => c.name -> c)
}
Success(())
}
else {
db.setVersion(theHiveSchema.name, theHiveSchema.operations.lastVersion)
db.setVersion(cortexSchema.name, cortexSchema.operations.lastVersion)
db.tryTransaction { implicit graph =>
profiles ++= Profile.initialValues.flatMap(p => profileSrv.createEntity(p).map(p.name -> _).toOption)
resolutionStatuses ++= ResolutionStatus.initialValues.flatMap(p => resolutionStatusSrv.createEntity(p).map(p.value -> _).toOption)
Expand All @@ -188,6 +192,7 @@ class Output @Inject() (
users ++= User.initialValues.flatMap(p => userSrv.createEntity(p).map(p.login -> _).toOption)
Success(())
}
}
}

override def endMigration(): Try[Unit] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ object IntegrityCheck {
case FinishGlobal(name, cancel, result) =>
logger.info(s"End of global check of $name${if (cancel) " (cancelled)" else ""}:${result.map(kv => s"\n ${kv._1}: ${kv._2}").mkString}")
val state = states.getOrElse(name, CheckState.empty)
val newState = state.copy(dedupStats = state.dedupStats + result, globalCheckRequested = false, globalCheckIsRunning = false)
val newState = state.copy(globalStats = state.globalStats + result, globalCheckRequested = false, globalCheckIsRunning = false)
onMessage(states + (name -> newState))

case CancelCheck =>
Expand Down

0 comments on commit c0c2442

Please sign in to comment.