How can we help you today? How can we help you today?

Using Flyway with the aws-mysql-jdbc driver - how to set custom driver?

Hello! I'm trying to set up Flyway to use AWS own jdbc driver for MySQL, see https://github.com/awslabs/aws-mysql-jdbc. These connection URL:s start with `jdbc:mysql:aws:`. If I use flyway-core 9.16.1 together with flyway-mysql, this works in that it will accept the URL:s and run migrations. However, it will still use the MySQL Connector/J driver. I would prefer to not have that on the classpath at all. If I don't, it fails:

   org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver: com.mysql.cj.jdbc.Driver => Check whether the jar file is present

So I've been trying to set the driver to the aws-jdbc-sql one, using the method described here: https://documentation.red-gate.com/fd/driver-184127498.html

However, there exists no method "driver" on the FluentConfiguration object returned by Flyway.configure(). It also doesn't seem to respect if try to set it through Java properties.

Is there a way to make this work?

Regards, Simon
skagedal
0

Comments

6 comments

  • Peter_Laws
    Thanks for your query skagedal,

     Your approach is what I'd expect, the driver configuration is the appropriate way to define this and once established there should be no need to remove the default driver as it won't be used.

    Thought evidently there's some configuration complication, does yours look roughly like this?

    Flyway.configure() 
        .driver("com.mysql.cj.jdbc.Driver") 
        .load()
    

    Peter_Laws
    0
  • skagedal
    Hi! Yes, the problem is that that code does not compile – there is no such method "driver". Here's some example output compiling that code, with Flyway 9.16.3 from Maven Central on the class path:


    $ ./gradlew build > Task :app:compileJava FAILED /Users/simon/code/flyway-driver/app/src/main/java/tech/skagedal/flywaydriver/App.java:10: error: cannot find symbol Flyway.configure().driver("com.mysql.cj.jdbc.Driver"); ^ symbol: method driver(String) location: class FluentConfiguration 1 error FAILURE: Build failed with an exception.


    It can also be seen by looking at the code: https://github.com/flyway/flyway/blob/main/flyway-core/src/main/java/org/flywaydb/core/api/configuration/FluentConfiguration.java – there is no `driver` method here.
    skagedal
    0
  • skagedal
    Hi! Yes, the problem is that this code does not compile – there is no method "driver" on the `FluentConfiguration` object returned by `Flyway.configure()`.

    I've tested this with `flyway-core` version 9.16.3 from Maven Central, and it also matches what I see in code: https://github.com/flyway/flyway/blob/main/flyway-core/src/main/java/org/flywaydb/core/api/configuration/FluentConfiguration.java


    skagedal
    0
  • Peter_Laws
    Oh I see what you mean now, and that's also presumably why you were looking at the jdbcProperties parameters as a consequence on the driver comments!

    Apologies, I've caught up now. While the gradle plugin would need slightly different config, since you linked the page that references such earlier I'm going to assume you allowed for that. Regardless, I'd have expected the flyway core part to work.

    I'll dig into it and come back to you.
    Peter_Laws
    0
  • Peter_Laws
    Thanks for bearing with me Simon,

    This does appear to be an oversight on our part, I've raised a request to get it looked at, as it presently stands our documentation is misleading.

    As a work around, you could address the underlying object via ClassicConfiguration the same way the FluentConfiguration typically would, it lacks some of the nicety, but should allow you to progress.

    E.G

    ClassicConfiguration config = new ClassicConfiguration();
    config.setUrl("jdbc:h2:mem:db");
    config.setUser("sa");
    config.setDriver("org.amazon.aura.Driver"); 
    Flyway flyway = new Flyway(config);
    Peter_Laws
    0
  • skagedal
    Ah, thanks a lot Peter! I'll give that a try!
    skagedal
    0

Add comment

Please sign in to leave a comment.