Search code examples
sqlcommentsdatabase-migrationflyway

How to add a comment to flyway migration


I am trying to make my big migration more self explaining and that's why I need to add some comments to it. However, I tried a few approaches and haven't succeeded with them. I tried:

  • //
  • #
  • <!-- TEXT -->

Error:

   SQL State  : 42601
   Error Code : 0
   Message    : ERROR: syntax error at or near "//"
   Position: 1

Is there a way I can add a comment to flyway SQL migration?


Solution

  • The following should work on all supported databases:

    /* Single line comment */
    
    /*
    Multi-line
    comment
    */
    
    -- Sql-style comment
    

    And additionally on MySQL and MariaDB:

    # MySQL-style single line comment
    

    When we were upgrading to spring-boot 2.5 we found that there is need to have a space after first two hyphens -- with SQL style comments