SQL output by using the servlet listener

Hi Nathan,

in the Liquibase documentation the feature of writing the sql statements to standard out instead of executing it is introduced. Unfortunately it’s only documented for running Liquibase from the command line or Grails. I use the servlet listener and wonder how to configure the “output-only” behaviour. It would be great to redirect the output to a self defined stream or something like that.

Just to let you know some facts about the intention of my question: Often customers don’t allow the database user of the application to create and/or alter tables. If Liquibase detects that the user has insufficient privileges (I don’t know how to detect this either, but that’s another topic…), the SQL script should be generated, so a database administrator can execute it.

Thanks for your help.

Kind regards
Oliver

There isn’t that feature in the servlet listener because the theory is that you use the listener to auto-update your database as part of application start-up.  If you are needing a script for updating, you are going to have to generate it at some point before the application starts up, which is where Ant, command line, maven, grails, etc. would be used. 

As long as you have a database with the same databasechangelog table as your production database, an upgrade script generated with ant/maven/command line can be checked and ran against the production database before starting the application server, in which case you do not need to use the liquibase servlet listener.

Nathan

Hi Nathan,

thanks for your answer. The theory is comprehensible. I would like to give an example where it would be very helpful if the application decides at runtime which updates have to be executed:

You have a product with 300 customers and you do not know which version of your application the currently use in production. Furthermore you don’t know if the database user of the application has DDL privileges.

You recommended to generate an update script by using ant/maven/command line, but how to know what’s the base version. Every customer might have different versions of the database. Even if I know which version the customer has, I would have to deliver a personal update script to everyone of them based on the version he uses. One of my main reason why I would like to introduce Liquibase is to reduce the complexity for building releases. That’s the reason why it would be great if Liquibase could support this aim.

Anyway, it’s your decision which features are included in Liquibase. It’s easy to writer an own ServletListener which satisfies my claims. Unfortunately the shipped ServletFilter doesn’t offer good options to extend/customize the implementation. It would be helpful to modularize the ServletListener by splitting the methods and by providing protected (call back) methods. Currently my Session Listener doesn’t extend the shipped one and I had to copy a lot of code, so I have to check for chnages in the implementation on every Liquibase release. It’s just a suggestion… :wink:

Kind regards
Oliver