Skip to content

Document the supported Flyway bootstrap for jdbc:libsql: URLs #263

Closed

Description

@magnusp

Goal

Document, and cover with a test, how to point Flyway at a libSQL database:
pass a DataSource, or use URL configuration with the jdbc:sqlite: alias and
an explicit driver class.

Why

Flyway resolves its database plugin from the URL before it opens a connection,
and it never asks DriverManager which driver accepts the URL. As a result:

  • jdbc:libsql: is not claimed by Flyway's SQLite plugin, which accepts only
    jdbc:sqlite:, jdbc:sqldroid: and the p6spy prefixes:

    No Flyway database plugin found to handle jdbc:libsql:********
    
  • jdbc:sqlite: is claimed, but Flyway's plugin resolves the driver to
    org.sqlite.JDBC. Programmatic Flyway.configure().dataSource(url, ...)
    builds the DriverDataSource eagerly and passes a null driver class, so a
    later driver(...) is ignored:

    No JDBC driver found to handle jdbc:sqlite:********
    

This is not fixable inside the driver. It is a configuration and documentation
gap.

Workarounds that work today

  • DataSource (Spring Boot, HikariCP, any pool) with either jdbc:libsql:
    or jdbc:sqlite:. Pinned by
    FlywayMigrationIT#migratesThroughADataSource.
  • URL + explicit driver with the jdbc:sqlite: alias, for example
    Flyway.configure(new ClassicConfiguration()) with setUrl(...) and
    setDriver("io.github.magnusp.libsql.jdbc.LibsqlDriver"), or the equivalent
    Flyway Maven plugin / flyway.properties url and driver settings. Pinned
    by FlywayMigrationIT#migrateWithUrlConfigurationAndExplicitDriver.
  • jdbc:libsql: cannot be used with URL-based configuration at all, even with
    an explicit driver, because the plugin lookup fails first. Pinned by
    FlywayKnownGapsIT#libsqlUrlIsNotRecognizedByFlyway.

Session-state note

Flyway's initSql / afterConnect cannot tune connection-scoped state such as
PRAGMA foreign_keys: each auto-commit statement runs on a fresh Hrana stream
(see #83). Configure such state in the DataSource/pool, or run the statements in
an explicit transaction. The Flyway clean() consequence is tracked in #258.

Where

Verification

  • The documented snippets run against the pinned sqld container.
  • ./mvnw -pl libsql-jdbc -am verify -Dit.test='Flyway*IT'
  • ./mvnw spotless:check

Found while adding the Flyway integration tests in #259.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority: edge case, feature gap, or test/process improvementdocumentationImprovements or additions to documentationjavaPull requests that update java code

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions