Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flyway fails as SQLDroid misreports SQLite version as 0.0 #2409

Closed
beyondlov1 opened this issue Jun 7, 2019 · 2 comments

Comments

@beyondlov1
Copy link

commented Jun 7, 2019

Which version and edition of Flyway are you using?

5.2.4 or 6.0.0-beta2

If this is not the latest version, can you reproduce the issue with the latest one as well?

(Many bugs are fixed in newer releases and upgrading will often resolve the issue)

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Android, Gradle plugin

Which database are you using (type & version)?

sqlite 3.9.2

Which operating system are you using?

ubuntu 18.04

What did you do?

(Please include the content causing the issue, any relevant configuration settings, the SQL statement that failed (if relevant) and the command you ran.)

I use flyway on Android, but it complaines the version of my sqlite. This is the code:

DroidDataSource dataSource = new DroidDataSource(getPackageName(), "test.db");
        ContextHolder.setContext(this);
        Flyway flyway = Flyway.configure()
                .dataSource(dataSource)
                .baselineOnMigrate(true)
                .load();
        flyway.migrate();

gradle:

    implementation 'org.flywaydb:flyway-core:6.0.0-beta2'
    implementation 'org.sqldroid:sqldroid:1.1.0-rc1'
What did you expect to see?
What did you see instead?
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.beyond.note5, PID: 14720
    java.lang.RuntimeException: Unable to create application com.beyond.note5.MyApplication: org.flywaydb.core.internal.exception.FlywayDbUpgradeRequiredException: SQLite upgrade required: SQLite 0.0 is outdated and no longer supported by Flyway. Flyway currently supports SQLite 3.0 and newer.
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5501)
        at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
        at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:360)
        at android.app.ActivityThread.handleBindApplication(<Xposed>)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1575)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6236)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
     Caused by: org.flywaydb.core.internal.exception.FlywayDbUpgradeRequiredException: SQLite upgrade required: SQLite 0.0 is outdated and no longer supported by Flyway. Flyway currently supports SQLite 3.0 and newer.
        at org.flywaydb.core.internal.database.base.Database.ensureDatabaseIsRecentEnough(Database.java:151)
        at org.flywaydb.core.internal.database.sqlite.SQLiteDatabase.ensureSupported(SQLiteDatabase.java:54)
        at org.flywaydb.core.Flyway.execute(Flyway.java:488)
        at org.flywaydb.core.Flyway.migrate(Flyway.java:142)

@axelfontaine axelfontaine changed the title SQLite 0.0 is outdated and no longer supported by Flyway. Flyway currently supports SQLite 3.0 and newer Flyway fails as SQLDroid misreports SQLite version as 0.0 Jun 8, 2019

@axelfontaine axelfontaine added this to the Flyway 6.0.0 milestone Jun 8, 2019

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Jun 8, 2019
@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 8, 2019

Thank you very much for reporting. Arrgghh these SQLite JDBC drivers are really hit and miss! We have removed the check. Could you file an issue with SQLDroid, so they actually fix this in the future?

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Jun 8, 2019
@jeffque

This comment has been minimized.

Copy link

commented Aug 2, 2019

As this is not yet published (and I needed it, like, for yesterday), I have workedaround like this:

Tested for Flyway 5.2.4, Java API; SQLDroid 1.0.3, but as this is proxy, should work also for 1.1.0-rc1

  private void createDatasource(String dbName) {
    DroidDataSource dds = new DroidDataSource(PACKAGE_NAME, dbName);
    // DataSourceHasFilename extends DataSource + getDbFilename method
    this.sds = (DataSourceHasFilename) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {DataSourceHasFilename.class }, (proxy, method, args) -> {
      switch (method.getName()) {
      case "getDbFilename": //ignore this, I need this method to open the same database in a Flutter app
        return "/data/data/" + dds.getPackageName() + "/" + dds.getDatabaseName() + ".db";
      case "getConnection": // wrapping the connection to wrap the databasemetadata object
        return connWrapper((Connection) method.invoke(dds, args));
      }
      return method.invoke(dds, args);
    });

    getTenantFlywayConf(sds).migrate();
  }

  public Connection connWrapper(Connection c) {
    return (Connection) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { Connection.class }, (proxy, method, args) -> {
      switch (method.getName()) {
      case "getMetaData": // wrapping the databasemetadata
        return metadataWrapper((DatabaseMetaData) method.invoke(c, args));
      }
      return method.invoke(c, args);
    });
  }

  public DatabaseMetaData metadataWrapper(DatabaseMetaData dmd) {
    return (DatabaseMetaData) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { DatabaseMetaData.class }, (proxy, method, args) -> {
      switch (method.getName()) {
      case "getDatabaseMajorVersion": // faking the results =D
        return 3;
      case "getDatabaseMinorVersion":
        return 7;
      }
      return method.invoke(dmd, args);
    });
  }

  public static Flyway getTenantFlywayConf(DataSource ds) {
    return Flyway.configure()
        .dataSource(ds)
        .target(MigrationVersion.LATEST)
        .baselineOnMigrate(true)
        .baselineVersion(MigrationVersion.fromVersion("0"))
        .load();
  }

Waiting for the 6.0.0 to remove this workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.