Redgate Flyway

Replacing Redgate regex rules with SQLFluff rules

We've been working on creating SQLFluff alternatives for our custom regex-based SQL linting rules. This will help us leverage the capabilities of SQLFluff for better SQL code quality and consistency.

  • SQLFluff is more than just simple text pattern matching (so for example, commented-out SQL won't trip it up like it would Regex)
  • You can configure your rules in one place (the sqlfluff.cfg file)
  • You can manage rule exceptions in a more fine-grained manner using SQLFLuff's noqa mechanism
  • It's supports many more dialect variants so it's likely to do a better job on less common DBs out of the box
  • Many SQLFluff rules have configuration options to make it easier to customize to your requirements via configuration rather than rewriting the rule

The engine that powers regex rules will remain and customers can continue to use it however we don't plan to release new rules in this format.

When will anything change ?

We will stop shipping our regex rules (the .toml files in the rules/ folder of each Flyway release) in the near future.

If you were relying on them being in the Flyway installation then this will change. If you have your own copies then nothing will change - we're not removing the ability to use regex rules, just stopping shipping these ones.

We have already been shipping the replacement SQLFLuff rules so you may have noticed duplicate alerts from the regex and SQLFluff engines.

How to change over

As you are using Regex rules then you have an Enterprise license and so also have access to the bundled version of SQLFluff that includes Redgate's rules.

You will need to configure SQLFLuff to apply the rules that you are interested in.

  • Identify the replacement rule you need to use (see the table below)
  • Copy the conf/sqlfluff.cfg file from the Flyway installation into your project - this configuration is your definition of what good SQL looks like to your organization.
  • Use the check.rulesConfig parameter to tell Flyway where to find this configuration. Flyway will default to the one in the Flyway installation but that is just intended to help you get started
  • Update your sqlfluff.cfg to include the relevant Redgate SQLFluff rules
    • A number of rules also have configuration options so don't forget to update them if relevant
  • Remove the old regex rule(s)
    • you can just delete them
    • if you don't need this capability at all then it can be disabled using the check.regexEnabled parameter

Redgate regex -> Redgate SQLFLuff rule mapping


Regex RuleRedgate SQLFLuff equivalentDetails
RX001RG01Drop Table
RX002RG08Change password
RX003RG13TRUNCATE statement used
RX004RG14DROP COLUMN statement used
RX005RG07GRANT TO PUBLIC statement used
RX006RG07GRANT WITH GRANT OPTION statement used
RX007RG07GRANT WITH ADMIN OPTION statement used
RX008RG08ALTER USER statement used
RX009RG07GRANT ALL statement used
RX010RG11CREATE ROLE statement used
RX011RG08ALTER ROLE statement used
RX012RG16DROP PARTITION statement used
RX013RG15CREATE TABLE statement without a PRIMARY KEY constraint
RX014RG17No Table Description

...but I want to keep things the way they are

You absolutely can.

  • You should store regex the rules you use under your own VCS rather than solely relying on what is in the contents of a Flyway release
  • To avoid duplicate code analysis alerts you can remove the Redgate rules (numbered RGxx) from the project sqlfluff.cfg file

You will have a section that looks like this:

# Comma separated list of rules to check, default to all
rules = ambiguous,convention,structure,RG01,RG02,RG03,RG04,RG06,RG07,RG08,RG09

and you can just remove all the RG01,RG02... items and these rules will then not be run.


Didn't find what you were looking for?