Calling sql scripts with some parameters

Liquibase does have changelog parameter support (http://www.liquibase.org/documentation/changelog_parameters.html) which should work for both attributes in the XML and in sqlFile.

How you set them depends on how you are calling liquibase (command line, ant, etc)

Nathan

Ok Nathan, now I see.

We’re using Ant but not with the liquibase tasks. We’re calling liquibase scripts with Ant giving parameters like url, username…

I will do a refactor of this to use Liquibase Ant tasks as recommended here : http://www.liquibase.org/documentation/ant/index.html

(hoping I’ll still be able to update/rollback my different targets as I do now)

Regards,

Frederic

Hi,

I’m using Oracle CDC for which I have scripts to add columns, create tables…

With liquibase (3.3) I have to call those scripts with the <sqlFile> tag.

I can call them while I’m connected to the database connection where the published tables are stored.

My problem is that I need to have the source database reference also, as the Oracle commands needs it to create the link between source and target tables.

I already have the parameters in properties file, and can connect to the target tables scheme.

Is there a way to pass some parameters to the sql script in order to tell it what is the source scheme it needs?

Best regards,

Frederic

Same thing to be able to change for example the tablespaces used depending on the target database:

<createTable tableName=“THE_TABLE_NAME” tablespace="${ONE_TABLESPACE}">

with MY_TABLESPACE name defined in some properties.

Is this goal already reachable?

If you don’t want to refactor your ant tasks, you can pass in paramemer values though the command line or set them as system properties.

Nathan

Well I did the refactor, and it’s working fine !

Thanks for all.

So now I use Ant to call directly liquibase, giving some liquibase:changeLogParameters that are directly used by the scripts called with , used as : ‘${databaseCdcTarget}’ for example.

It now works very well but it was quite a mess to set up as I ran throught a lot of path problems.

I will therefore open a new thread about not logged path errors.

Also, previoulsy I was calling one target with parameters to give the command update/updateSql/rollback/rollbackSQL and to add the rollback tag for example. But now I have 4 targets. and I can’t use the same target for update and updateSQL because if I set outputFile="" (if I don’t want to log the sql requests but want to really update) then I have an error. So I duplicated liquibase:updateDatabase, one with outputFile and one without. Is there a way to avoid that?

Regards

Good that worked. I don’t think there is a way to combine your targets, but I haven’t used the ant tasks for a while. They were redone a bit with 3.3.0, is that the version you are using?

Nathan

Correct. Each task is an independent action so if you need to call updateDatabase with and without an output file that would be two separate task calls (i.e. two separate elements). That is the nature of any Ant task and the command line does have that advantage in some cases.

You can combine multiple tasks into a single Ant target if you always want the two tasks to run at the same time.

If you are having any issues with the tasks or have any feedback, I would be happy to help. I am always looking to improve the tasks.