Making SQLFluff code analysis more accessable
Published 03 July 2025
Flyway can run a set of static code analysis tools across your migrations using the check -code configuration which tests your SQL against one of several analysis engines (SQLFluff & Regex)
If you have an Enterprise license for Flyway then we've made it even easier to add SQLFluff to your code analysis tools.
Previously, Flyway relied on you having SQLFluff installed externally to Flyway and we know this caused problems for some people.
You would see this message:
Flyway SqlFluff code analysis requires Python 3, pip and SqlFluff version 1.2.1 or greater, preferably version 3.4.0
Run 'pip install sqlfluff==3.4.0' to install SqlFluff if you would like to access this function
What we've done is to wrap SQLFluff as an executable and include it in the Flyway CLI download (from Flyway v11.10.0)
(The Flyway Docker images have always come with SQLFluff included but Docker isn't a route that every organization can use)
Enabling the feature
From Flyway 11.16.0 this feature is now enabled by default so there is no need to set any flags for this. Should you want to switch to your own installed version of SQLFluff then you can do so by setting the environment variable to false like this:
Powershell
$env:FLYWAY_ENV_NATIVE_SQLFLUFF = 'false'
Bash
export FLYWAY_ENV_NATIVE_SQLFLUFF='false'
What you'll see with the shipped SQLFluff integration
Flyway will operate exactly as it does if you had SQLFluff installed separately from Flyway
Database: jdbc:sqlserver:// ... (Microsoft SQL Server 16.0)
SQLFluff code analysis summary:
Total analysis: 1 SQL file(s) scanned with dialect TSQL applied
Files with violations: 1 Violations: 17
There are now new rule definitions available that are shipped with the built-in version, see Redgate SQLFluff Rules Library
Observations
This doesn't work on Ubuntu 20.04 (and older) as a dependency can't be satisfied. You'll see something like this:
[PYI-2516:ERROR] Failed to load Python shared library '/tmp/_MEIP3AK4i/libpython3.10.so.1.0': /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.35' not found (required by /tmp/_MEIP3AK4i/libpython3.10.so.1.0)