rolang / dumbo

Simple database migration tool for Postgres with skunk on JVM and Native
MIT License
26 stars 3 forks source link

java.nio.file.FileSystemNotFoundException: null #14

Closed jbohman closed 11 months ago

jbohman commented 11 months ago

When testing this library we noticed that it was not possible to run it through sbt with scala 2.13.

It results in this exception:

java.nio.file.FileSystemNotFoundException: null
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:156)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:142)
        at java.base/java.nio.file.Path.of(Path.java:208)
        at java.base/java.nio.file.Paths.get(Paths.java:98)
        at dumbo.ResourceFilePath$.$anonfun$fromResourcesDir$3(ResourceFilePath.scala:25)
        at delay @ dumbo.ResourceFilePath$.$anonfun$fromResourcesDir$2(ResourceFilePath.scala:24)
        at delay @ dumbo.ResourceFilePath$.fromResourcesDir(ResourceFilePath.scala:22)
        at flatMap @ dumbo.ResourceFilePath$.fromResourcesDir(ResourceFilePath.scala:22)

For this code:

    Dumbo
      .withResourcesIn[F]("db/migration")
      .apply(
        sessionResource = Session.single[F](
          host = dbConf.host.value,
          port = dbConf.port.value,
          user = dbConf.user.value,
          database = dbConf.db,
          password = dbConf.password.value.some,
        ),
        defaultSchema = schema.getOrElse("public"),
      )
      .runMigration
      .flatMap { result =>
        Async[F].delay(println(s"Migration completed with ${result.migrationsExecuted} migrations"))
      }

After digging a bit it seems like Paths.get does not handle jar files jar:file:/Users/.../target/bg-jobs/sbt_fac89327/job-21/target/92a8dfce/9d592533/test_2.13-27e70d62.jar!/db/migration

Any advice on how to proceed?

rolang commented 11 months ago

Hi @jbohman , thanks for reporting, looks like I removed the jar file reading capability (unintentionally) which Scala 2 still relies on in the latest update ^^. Will fix asap and try to cover it in a CI job. It went unnoticed because the resources are not packaged into jars in tests.

rolang commented 11 months ago

There is also an alternative way you can pass the resources by hand which still should work. To take the example from the readme like that:

import cats.effect.{IO, IOApp}
import dumbo.{Dumbo, ResourceFilePath}
import natchez.Trace.Implicits.noop

object ExampleApp extends IOApp.Simple {
  override def run: IO[Unit] = Dumbo
    .withResources[IO](
      List(
        ResourceFilePath("/db/migration/V1__test.sql"),
        ResourceFilePath("/db/migration/V2__test_b.sql"),
        ResourceFilePath("/db/migration/V3__test_c.sql"),
      )
    )
    .apply(
      sessionResource = skunk.Session.single[IO](
        host = "localhost",
        port = 5432,
        user = "postgres",
        database = "postgres",
        password = Some("postgres"),
      ),
      defaultSchema = "public",
    )
    .runMigration
    .flatMap { result =>
      IO.println(s"Migration completed with ${result.migrationsExecuted} migrations")
    }
}

Once the issue is fixed it can be changed to use the location with Dumbo.withResourcesIn[F]("db/migration")

rolang commented 11 months ago

@jbohman it should be fixed now in the release v0.0.5