🚧 Run Flyway migration before core is started
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 6 Apr 2025 09:49:32 +0000 (11:49 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 6 Apr 2025 16:20:08 +0000 (18:20 +0200)
src/main/java/net/pterodactylus/sone/main/SonePlugin.java
src/test/kotlin/net/pterodactylus/sone/main/SonePluginTest.kt

index a0c8489..7cb6491 100644 (file)
@@ -45,6 +45,7 @@ import com.google.inject.*;
 import com.google.inject.Module;
 import com.google.inject.name.*;
 import kotlin.jvm.functions.*;
+import org.flywaydb.core.Flyway;
 
 /**
  * This class interfaces with Freenet. It is the class that is loaded by the
@@ -194,6 +195,10 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                this.pluginRespirator = pluginRespirator;
 
                Injector injector = createInjector();
+
+               Flyway flyway = injector.getInstance(Flyway.class);
+               flyway.migrate();
+
                core = injector.getInstance(Core.class);
 
                /* create web of trust connector. */
index 27edbbd..56b9e83 100644 (file)
@@ -20,6 +20,9 @@ import org.mockito.Mockito.*
 import java.io.*
 import java.util.concurrent.atomic.*
 import kotlin.test.*
+import org.flywaydb.core.Flyway
+import org.junit.Rule
+import org.junit.rules.TemporaryFolder
 
 /**
  * Unit test for [SonePlugin].
@@ -34,6 +37,10 @@ class SonePluginTest {
        private val clientCore = deepMock<NodeClientCore>()
        private val uskManager = deepMock<USKManager>()
 
+       @Rule
+       @JvmField
+       val tempFolder = TemporaryFolder()
+
        init {
                whenever(node.getClientCore()).thenReturn(clientCore)
                whenever(pluginRespirator.node).thenReturn(node)
@@ -41,6 +48,11 @@ class SonePluginTest {
                whenever(clientCore.getClientContext()).thenReturnMock()
        }
 
+       @BeforeTest
+       fun setNodeUserDir() {
+               whenever(node.userDir).thenReturn(tempFolder.root)
+       }
+
        @Test
        fun `sone plugin can be started`() {
                sonePlugin.setLanguage(ENGLISH)
@@ -109,6 +121,13 @@ class SonePluginTest {
                assertThat(getInjected(TickerShutdown::class.java), notNullValue())
        }
 
+       @Test
+       fun `flyway is told to migrate`() {
+               sonePlugin.runPlugin(pluginRespirator)
+               assertThat(getInjected(Flyway::class.java), notNullValue())
+               verify(getInjected(Flyway::class.java))!!.migrate()
+       }
+
        private class FirstStartListener(private val firstStartReceived: AtomicBoolean) {
                @Subscribe
                fun firstStart(@Suppress("UNUSED_PARAMETER") firstStart: FirstStart) {