manticore-projects / H2MigrationTool

A software tool for migration of an old H2 database into a new H2 database format automatically.
https://manticore-projects.com/H2MigrationTool/index.html
GNU General Public License v3.0
34 stars 3 forks source link

Tool does not seem to work with Windows File Paths #4

Closed Ulathar closed 2 years ago

Ulathar commented 2 years ago

Hey there,

just stumbeled across this tool and tried to give it a try but had some obsticales to overcome: To be able to execute the released JAR I had to lookup required dependencys in the jars manifest first and provide those jars alongside the main jar in /lib. No big deal, just wanted to point that one out (maybe add it to the readme?). Required libs which needs to be provided at runtime seem to be:

As soon as those are present the Tool runs fine (UI shows up and/or you can use the cli).

But after that I noticed that no matter what i try the tool fails right after the export step when it tries to create the new h2 Database from the generated .sql script. It looks like the jdbc paths are build wrong when running on a Windows maschine: (the problem here is the Drive letter followed by the ':'):

INFORMATION: Wrote H2-1.4.200 database to script: D:\Test\TestH2Database.sql
Exception in thread "main" java.lang.Exception: Failed to migrate the database.
        at com.manticore.h2.H2MigrationTool.main(H2MigrationTool.java:1149)
Caused by: java.lang.Exception: Failed to created new H2-2.1.210 database: D:\Test\TestH2Database
        at com.manticore.h2.H2MigrationTool.migrate(H2MigrationTool.java:922)
        at com.manticore.h2.H2MigrationTool.main(H2MigrationTool.java:1142)
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Allgemeiner Fehler: "java.nio.file.InvalidPathException: Illegal character [:] in path at index 3: //D:/Test/TestH2Database.210null"
General error: "java.nio.file.InvalidPathException: Illegal character [:] in path at index 3: //D:/Test/TestH2Database.210null" [50000-210]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:573)
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
        at org.h2.message.DbException.get(DbException.java:216)
        at org.h2.message.DbException.convert(DbException.java:414)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:340)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:122)
        at org.h2.Driver.connect(Driver.java:59)
        at com.manticore.h2.H2MigrationTool.createFromScript(H2MigrationTool.java:799)
        at com.manticore.h2.H2MigrationTool.migrate(H2MigrationTool.java:913)
        ... 1 more
Caused by: java.nio.file.InvalidPathException: Illegal character [:] in path at index 3: //D:/Test/TestH2Database.210null
        at java.base/sun.nio.fs.WindowsPathParser.nextSlash(WindowsPathParser.java:212)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:111)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
        at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
        at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
        at java.base/java.nio.file.Path.of(Path.java:147)
        at java.base/java.nio.file.Paths.get(Paths.java:69)
        at org.h2.store.fs.disk.FilePathDisk.isAbsolute(FilePathDisk.java:308)
        at org.h2.store.fs.FileUtils.isAbsolute(FileUtils.java:144)
        at org.h2.engine.ConnectionInfo.getName(ConnectionInfo.java:457)
        at org.h2.engine.Engine.openSession(Engine.java:49)
        at org.h2.engine.Engine.openSession(Engine.java:222)
        at org.h2.engine.Engine.createSession(Engine.java:201)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338)
        ... 5 more

So I took a quick look into the code and found two relevant occurences of "driver.connect(...)" in H2MigrationTool.java that look like this:

connection = driver.connect(
          "jdbc:h2://" + databaseFileName + ";ACCESS_MODE_DATA=r" + connectionParameters,
          properties);

In order to work properly with Windows filepaths something like this should work (using such connection strings in my own tool as well):

connection = driver.connect(
          "jdbc:h2:file:" + databaseFileName + ";ACCESS_MODE_DATA=r" + connectionParameters,
          properties);

Bringing me to the next point: I tried to change those code parts accordingly and rebuild it locally on my machine using the provided build.xml file but can't get it to build either because of some absolute paths in the whole build xmls pointing to specific local paths and missing ClassPath configurations (those libs again mentioned above).

All in all very nice idea but does not seem to work poperly (yet) on Windows maschines unless I overlooked something.

manticore-projects commented 2 years ago

Greetings!

Thank you a lot for the feedback, dankeschoen! On the concerns:

1) Libraries

We have provided FAT Jars including everything, here on GitHub. Although we will commit a Gradle build soonest.

2) On the Windows Paths

Point taken, I have never used Windows in my life but I will try to get a VMWare and test and adjust where necessary.

Give me 1-2 days please. Cheers

Ulathar commented 2 years ago

Oh I am not asking / demanding anything, was able to run some test migrations using my Raspberry Pi. So Windows Support would be a bonus, but thanks for your efforts and quick response ;-)!

HerbJiang commented 2 years ago

The release v1.1 H2MigrationTool.jar seems not a FAT jar, right? Just make sure I don't missed anything.

manticore-projects commented 2 years ago

Greetings Herb.

https://github.com/manticore-projects/H2MigrationTool/releases/download/1.1/H2MigrationTool.jar should contain everything (="Fat Jar"). What exactly is not working please or missing?

HerbJiang commented 2 years ago

Using open jdk 11.0.2 Run: java -jar H2MigrationTool.jar Will get

Error: Unable to initialize main class com.manticore.h2.H2MigrationTool
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
manticore-projects commented 2 years ago

Sorry, I will have to fix that of course.

manticore-projects commented 2 years ago

Thanks again for reporting, I have fixed that with release 1.2