From 158da0f1ccf9c91f964ee42ad85d815353696d47 Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Mon, 18 Nov 2024 18:41:55 -0600 Subject: [PATCH] Minor fix for upgrades with applyToNew false --- core/src/main/scala/lightdb/LightDB.scala | 19 +++++++++++-------- .../main/scala/lightdb/spatial/Spatial.scala | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/main/scala/lightdb/LightDB.scala b/core/src/main/scala/lightdb/LightDB.scala index 1213644..80a896f 100644 --- a/core/src/main/scala/lightdb/LightDB.scala +++ b/core/src/main/scala/lightdb/LightDB.scala @@ -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(() => { @@ -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") } diff --git a/core/src/main/scala/lightdb/spatial/Spatial.scala b/core/src/main/scala/lightdb/spatial/Spatial.scala index 28a6d66..aba7272 100644 --- a/core/src/main/scala/lightdb/spatial/Spatial.scala +++ b/core/src/main/scala/lightdb/spatial/Spatial.scala @@ -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 = {