Redgate Flyway

Tutorial - Run code review on deployment script

 Flyway Enterprise

Pre-requisites

  • Ensure that Flyway is installed and available on your path
  • Ensure that any secrets necessary for database connection auth are available

Commands to run

  1. Use flyway prepare to generate your deployment script:
    flyway prepare -source=schemaModel -target=Prod

    This defaults to adding a D__deployment.sql file into a deployments folder in your current directory.


  2. Run flyway check -code to run static code analysis checks against the generated deployment script:
    flyway check -code -scope=script -scriptFilename="deployments/D__deployment.sql" -failOnError=true

    The failOnError setting is optional, and causes the command to return an error if any code violations are detected.


Pre-requisites

How to view code violations while generating a deployment script

  1. Navigate to the Deploy changes page
  2. Select the objects you want to include in your deployment script ,then click the Deploy button on the top right corner.


  3. Once the deployment script is generated, if it contains any violations, a grey button will be shown indicating the total number of violations found from running code review. Clicking this toggles the code review side bar for the script. If no violations are found then a green check along with the message "Code review passed" will be shown instead.


    Understanding the Code Review Side bar

    • The sidebar shows the details of each code review violation, ordered by their appearance in the script and grouped by severity.
    • For each violation you can,
      • Click on the violation - This navigates the script editor to where the issue occurs.
      • Ignore - Clicking this dismisses the violation by adding a comment at the end of the line. (Note: This is only available for certain rule types).
      • Learn more - Clicking this opens documentation for the relevant rule in your browser.
    • In addition, you can also navigate between issues using the Next and Previous buttons to step through the violations sequentially.

  4. To close the sidebar, click the grey issues button which was used in step 3 to toggle open sidebar.

    Code review supports a maximum of 60,000 lines per script by default. If this limit is exceeded, code review will not run and no violations will be shown.

Related command reference




Didn't find what you were looking for?