1

Looking at this reference: https://docs.kony.com/konylibrary/konyfabric/kony_fabric_manual_install_guide/Content/FlywayNew.htm

It says the Google Cloud SQL drivers need to be installed manually for the flyway cli, but how do I install them manually? I can't find any documentation on it.

EDIT: I added this to my flyway.conf: flyway.jarDirs=/Users/my/flyway

Then I downloaded the driver into that folder: mvn dependency:get -Ddest=/Users/my/flyway -Dartifact=com.google.cloud.sql:postgres-socket-factory:1.3.0

but when I try to use it I get this error: The SocketFactory class provided com.google.cloud.sql.postgres.SocketFactory could not be instantiated.

EDIT: this is the debug output when running flyway baseline against my DB

Flyway Community Edition 7.10.0 by Redgate
DEBUG: AWS SDK available: false
DEBUG: Google Cloud Storage available: true
DEBUG: Scanning for filesystem resources at 'sql'
ERROR: Skipping filesystem location:sql (not found).
ERROR: Unexpected error
org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to obtain connection from database (jdbc:postgresql:///mydb  ?unixSocketPath=/var/run/cloudsql/  &cloudSqlInstance=my-gcp-project:us-central1:my-cloudsql-instance   &socketFactory=com.google.cloud.sql.postgres.SocketFactory  &user=jenkins-flyway    &password=******************************************) for user 'null': The SocketFactory class provided com.google.cloud.sql.postgres.SocketFactory  could not be instantiated.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State  : 08006
Error Code : 0
Message    : The SocketFactory class provided com.google.cloud.sql.postgres.SocketFactory    could not be instantiated.

    at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:71)
    at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:68)
    at org.flywaydb.core.Flyway.execute(Flyway.java:510)
    at org.flywaydb.core.Flyway.baseline(Flyway.java:406)
    at org.flywaydb.commandline.Main.executeOperation(Main.java:226)
    at org.flywaydb.commandline.Main.main(Main.java:149)
Caused by: org.postgresql.util.PSQLException: The SocketFactory class provided com.google.cloud.sql.postgres.SocketFactory   could not be instantiated.
    at org.postgresql.core.SocketFactoryFactory.getSocketFactory(SocketFactoryFactory.java:43)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:182)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
    at org.postgresql.Driver.makeConnection(Driver.java:465)
    at org.postgresql.Driver.connect(Driver.java:264)
    at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnectionFromDriver(DriverDataSource.java:268)
    at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnection(DriverDataSource.java:232)
    at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:55)
    ... 5 more
Caused by: java.lang.ClassNotFoundException: com.google.cloud.sql.postgres.SocketFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at org.postgresql.util.ObjectFactory.instantiate(ObjectFactory.java:46)
    at org.postgresql.core.SocketFactoryFactory.getSocketFactory(SocketFactoryFactory.java:39)
    ... 13 more
red888
  • 27,709
  • 55
  • 204
  • 392

1 Answers1

1

This is for Postgres on Google Cloud, yes?

The intention is that you put driver JARs into the drivers folder inside the Flyway product (not 100% sure for v4.0 as that's very elderly now - 7.11 is current). jarDirs should work, but it's the intended place for Java-based migrations.

However, it looks like a problem within the driver. Are you making sure to put all dependencies of the driver there too? Could you provide a full debug log (that is, flyway migrate -X) with exception details so we could take a look?

EDIT: It's definitely a problem within the driver, looking at that debug log - it's not able to instantiate a class internal to the driver.

Julia Hayward
  • 1,987
  • 1
  • 14
  • 16
  • yes this is postgres cloud sql. My goal is to get the jdbc driver working so I can use IAM auth which is supported. hmm is there a way to run this without initiating a migration? I dont even have migration scripts yet. when I run `flyway migrate -X` I get `Unable to connect to the database`. is there a way to test the driver is working without actually hitting a database? – red888 Jul 01 '21 at 14:37
  • ok im dumb I just re-ran the command i was trying to run with -X. will post output – red888 Jul 01 '21 at 14:39