Skip to content

Commit

Permalink
Minor fix for upgrades with applyToNew false
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Nov 19, 2024
1 parent 6e173bb commit 158da0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/src/main/scala/lightdb/LightDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@ trait LightDB extends Initializable with FeatureSupport[DBFeatureKey] {
// Get applied database upgrades
val applied = appliedUpgrades.get()
// Determine upgrades that need to be applied
val upgrades = this.upgrades.filter(u => u.alwaysRun || !applied.contains(u.label)) match {
case list if !dbInitialized => list.filter(_.applyToNew)
case list => list
}
val upgrades = this.upgrades.filter(u => u.alwaysRun || !applied.contains(u.label))
if (upgrades.nonEmpty) {
scribe.info(s"Applying ${upgrades.length} upgrades (${upgrades.map(_.label).mkString(", ")})...")
doUpgrades(upgrades, stillBlocking = true)
doUpgrades(upgrades, dbInitialized = dbInitialized, stillBlocking = true)
}
// Setup shutdown hook
Runtime.getRuntime.addShutdownHook(new Thread(() => {
Expand Down Expand Up @@ -166,23 +163,29 @@ trait LightDB extends Initializable with FeatureSupport[DBFeatureKey] {
}

private def doUpgrades(upgrades: List[DatabaseUpgrade],
dbInitialized: Boolean,
stillBlocking: Boolean): Unit = upgrades.headOption match {
case Some(upgrade) =>
val continueBlocking = upgrades.exists(_.blockStartup)
if (stillBlocking && !continueBlocking) {
if (!dbInitialized && !upgrade.applyToNew) {
appliedUpgrades.modify { set =>
set + upgrade.label
}
doUpgrades(upgrades.tail, dbInitialized, continueBlocking)
} else if (stillBlocking && !continueBlocking) {
scribe.Platform.executionContext.execute(() => {
upgrade.upgrade(this)
appliedUpgrades.modify { set =>
set + upgrade.label
}
doUpgrades(upgrades.tail, continueBlocking)
doUpgrades(upgrades.tail, dbInitialized, continueBlocking)
})
} else {
upgrade.upgrade(this)
appliedUpgrades.modify { set =>
set + upgrade.label
}
doUpgrades(upgrades.tail, continueBlocking)
doUpgrades(upgrades.tail, dbInitialized, continueBlocking)
}
case None => scribe.info("Upgrades completed successfully")
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/lightdb/spatial/Spatial.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ object Spatial {
case Geo.MultiPolygon(polygons) => factory.createMultiPolygon(polygons.map(toShape).map {
case p: Polygon => p
}.toArray)
case Geo.GeometryCollection(list) => factory.createGeometryCollection(
list.map(toShape).toArray
)
}

def relation(g1: Geo, g2: Geo): SpatialRelation = {
Expand Down

0 comments on commit 158da0f

Please sign in to comment.