Flyway Native Connectors - MongoDB
Published 10 December 2024
What are we doing
The aim of this work is to allow Flyway to more easily use non-JDBC database connectivity. Flyway was originally built around JDBC so the structure of the API heavily influences Flyway's architecture and capabilities.
JDBC requires each request to be a separate statement. In some cases this is trivial but some databases have a complex SQL dialect requiring a complex parser with Flyway to break down a migration into it's component statements. This doesn't particularly add value, it's just a requirement of the JDBC API and so using a native driver, like mongosh, simplifies Flyway by leveraging existing capabilities of 3rd party tools.
In the case of MongoDB, the existing JDBC support is provided by a JDBC wrapper around mongosh but we're not totally happy with the library (it's not very performant in Flyway). By moving onto the new implementation you gain greater performance as Flyway can directly call mongosh) as well as allowing use of the JSON migration type that was previously not possible.
Availability
We're releasing this initially in the open source version of Flyway - getting MongoDB to work up till now required some effort of manually adding libraries to the released version and so we wanted to prioritize simplifying this.
Whilst the functionality is present in the Redgate edition, we've turned it off by default as the release already has a functioning MongoDB driver. Whilst it's possible to enable it in this release we don't suggest doing this yet and it is very unlikely to work with Flyway Desktop if you do.
How to use the new connector
We've tried to make it a straightforward transition and you can find out more at:
Work in progress
There are some limitations on the new driver as we wanted to get something into people's hands sooner. If something in this list affects you a lot then please comment on or add a +1
to the linked issue on the Flyway github repository. This will help us to prioritize issues.
You can revert to the legacy driver by setting the environment variable: FLYWAY_NATIVE_CONNECTORS
to be false in the environment you are running Flyway in.
Placeholders
These are used to parameterize deployments by replacing specific template strings in the migration script with externally-defined values
Issue on Flyway Repository
Mixed JSON/Javascript migrations with MongoDB
JSON migrations are executed using the MongoDB API and Javascript migrations use Mongosh and we can't currently support a mixture of types within one Flyway project.
Issue on Flyway Repository
Please let us know if this a significant constraint for you
Transactions
Flyway will not currently execute in transactions - this affects the default behavior as well as any explicit parameters that influence this (group, mixed, executeInTransaction).
Issue on Flyway Repository
Validate Migration Naming
This parameter is not currently supported
Issue on Flyway Repository
Callbacks
These are currently not supported so if you have any defined they won't be invoked.
Issue on Flyway Repository
Script Migrations
These are used to invoke a script rather than directly deploy changes to the database
Issue on Flyway Repository
Locking the Schema History Table
This is required if you have multiple Flyway instances attempting to change your database simultaneously. This is typically an issue when using the Flyway API in a java application.
Locking the schema history table is not currently supported