liquibase / liquibase-groovy-dsl

The official Groovy DSL for Liquibase
Other
83 stars 34 forks source link

Use triple-quoted strings in serializer #39

Closed ethanmdavidson closed 5 years ago

ethanmdavidson commented 5 years ago

When running the generateChangeLog command on an oracle database, I run into a couple of issues: 1) objects with multiple lines, e.g.

  changeSet(id: '1551192953968-7', author: 'edavidson (generated)') {
    createView(fullDefinition: true, viewName: 'FR_TEXT_COUNT') {
      "CREATE OR REPLACE FORCE VIEW FR_TEXT_COUNT (APPID, ITEMID, TYPE, PANEL, COUNT) AS select appid,itemid,type,panel,count(1) from fr_text_long
      group by appid,itemid,type,panel"
    }
  }

2) objects with double quotes, e.g.

changeSet(id: '1551192755372-1043', author: 'edavidson (generated)') {
    createView(fullDefinition: true, viewName: 'HOLSCHED') {
      "CREATE OR REPLACE FORCE VIEW HOLSCHED (PERNO, DAYNO, HOLDATE, DESCR) AS SELECT "PERNO","DAYNO","HOLDATE","DESCR" FROM PAYROLL.HOLSCHED"
    }
  }

It seems to me that we could solve both these problems by using triple-quoted strings when writing text bodies in the serializer, e.g:

serializedChange = """\
${serializedChange} {
  '''${textBody}'''
}"""

triple-single quotes would be easier here, but could still fail because oracle escapes single-quotes by using two (''), so when a string begins or ends with an escaped single-quote:

select 'the last char in this string is a single quote: ''' from dual;

the changelog generation would fail. A more robust solution would be to properly escape the text based on the sql dialect, but that's probably more trouble than it's worth. Triple-quoted strings should catch most cases, and it's easy enough to fix the generated changelog manually in the few cases that are missed.

Let me know your thoughts.

ethanmdavidson commented 5 years ago

Might also want to use them on propertyString as well, because some properties can have multiple line values:

changeSet(id: '1551192755372-32', author: 'edavidson (generated)') {
    createTable(remarks: 'This is a very long comment:
    heres the second line
    and heres another line', tableName: 'PAYMENT_PROC_DETAIL') {
stevesaliman commented 5 years ago

Version 2.0.3 of the Groovy DSL has been released with a fix for this issue.