I am using the following command to generate the change log
liquibase --schemas=test_schema --changelog-file=changelog.xml generateChangeLog
My liquibase.properties file is following:
url: jdbc:postgresql://xx.xxx.xx.xx:5432/test_db
driver: org.postgresql.Driver
username: testuser
password: test
logFile: liquibase.log
logLevel: debug
defaultSchemaName= test_schema
outputDefaultSchema= true
The output in the changelog.xml doesnt have a schemaName, I have multiple schemas in my database so I need schemaname in the changelog as well.
Output :
<changeSet author="user1 (generated)" id="xxxxxxxxxxxxx-1">
<createTable tableName="hello_world">
<column name="msg" type="CHAR(60)"/>
</createTable>
</changeSet>
Should be test_schema.hello_world or schemaname should be defined. Any suggestions what I am doing wrong?
Try to append currentSchema= to your db url
e.g.
command line:
--url="jdbc:postgresql://DB_HOST:DB_PORT/DB_NAME?currentSchema=SCHEMA_NAME"
liquibase.properties
url="jdbc:postgresql://DB_HOST:DB_PORT/DB_NAME?currentSchema=SCHEMA_NAME"
then call
liquibase <other command line params not part of liquibae.properties> generateChangeLog
According to this doc, the --schemas=<name1, name2> specifies database schemas you want to include. You might want to list out the schemas you want to include. Or you can simply use the liquibase --changeLogFile=dbchangelog.xml generateChangeLog command.
Related
We have been using Liquibase successfully for about six months. I'm moving to a new CI/CD pipeline using CircleCI and running into an error when running liquibase update over SSH.
Here's the command (after many iterations and much exploration of Liquibase documentation):
ssh $SSH_USER#$TEST_JOB_SSH_HOST "cd /var/www/html/liquibase ; liquibase --url=jdbc:$TEST_DB_URL/$TEST_DB_SCHEMA?user=$TEST_DB_USERNAME --username=$TEST_DB_USERNAME --password="\""$TEST_DB_PASSWORD"\"" --changelog-file=cl-main.xml --search-path=.,./ update --log-level 1"
The result:
However, the file does exist and can be seen here:
It was successfully executed several months ago using our old approach. Now I think Liquibase is just parsing files and somehow failing, likely because it's running from a different directory.
Here's a snippet from the changeset file:
<sqlFile dbms="mysql, mariadb"
encoding="UTF-8"
endDelimiter=";"
path="/../data/regional_integration_details-ingest_day-01.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
I think the issue is the leading slash.
The command I pasted above was based on reviewing this help document: https://docs.liquibase.com/concepts/changelogs/how-liquibase-finds-files.html
I'm struggling with the proper syntax to include in the --search-path parameter -- if that's even the correct parameter -- to make this work.
The nuclear option (yet to be tested) is to update all of our changesets, removing the leading slash. I'd prefer not to go that route.
Suggestions?
Edit 1
Updating to mention that the first four changesets are parsed successfully. They have path values like ../dirname/sqlscript_00.sql. Liquibase chokes on the first script with /../dirname/sqlscript_01.sql.
Also, we have no problems running Liquibase in local development, when we cd to /var/www/html/liquibase in our Docker containers and execute the liquibase update command.
Edit 2
Having CircleCI SSH directly into the server doesn't work, as it doesn't carry the variables over with it.
Passing the commands via SSH preserves those variables.
Liquibase removed support for absolute paths in v4.x.
My Liquibase property file looks like this
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath: C:\\Program Files\\sqljdbc_10.2\\enu\\mssql-jdbc-10.2.1.jre17.jar
changeLogFile: .\\home_changeLog.xml
url: jdbc:sqlserver://localhost;databaseName=home;integratedSecurity=false;trustServerCertificate=true;
username: user
password: password123
liquibase.hub.mode=off
I wanted to parametrise the database name used in the URL, tried by changing the URL to
url: jdbc:sqlserver://localhost;databaseName=${database};integratedSecurity=false;trustServerCertificate=true;
when I execute
liquibase --defaults-file="Home.properties" updatesql -database="home2"
Liquibase raise the error below
Unexpected error running Liquibase: Connection could not be created to
jdbc:sqlserver://localhost;databaseName=${database};integratedSecurity=false;trustServerCertificate=true;
with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. The
connection string contains a badly formed name or value.
If I execute
liquibase --defaults-file="Home.properties" updatesql --database="home2"
Unexpected argument(s): --database=home2
How can I parametrise the database name used in the URL? I would like to use the change log file rather than using different change log files for each environment.
Thanks
/i am trying to execute normal liquibase command for changelog in commandprompt but it is saying driver not exist/
liquibase --driver=oracle.jdbc.driver.OracleDriver --classpath=C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar --changeLogFile=db.changelog-1.0.xml --url="jdbc:oracle:thin:#localhost:1521:xe" --username=system --password=root update
/please any one tell me why throwing oracle.jdbc.driver.OracleDriver not found/
Change it to
liquibase --driver=oracle.jdbc.driver.OracleDriver \
--classpath=ojdbc6.jar \
....
I had to use:
--driver=oracle.jdbc.OracleDriver
Also please inlcude odbc jar in your property file.
Like:
driver: oracle.jdbc.OracleDriver
classpath: ojdbc6-2.0.jar
This will work.
is there a way of calling external scripts with liquibase in a staged manner?
I am looking for something similar to flyway callbacks to call external scripts like sh: https://flywaydb.org/documentation/callbacks.html
Example:
1) pre-migration: run sh script 1
2) run migration
3) post-migration: run sh script 2
4) If migration fails: run sh script 3
Basically a staged mechanism of calling external scripts as part of the migration steps.
I would appreciate your feedback.
Thank you
Tobi
You can run external programs (including sh scripts) with http://www.liquibase.org/documentation/changes/execute_command.html
If you want to run something before and after each migration run, you need to structure your master changelog such way:
<changeSet id="preMigration" runAllways="true">
...pre migration
</changeSet>
...all your migrations are here
<changeSet id="postMigration" runAllways="true">
...post migration
</changeSet>
And I'm not sure that there is error handler.
Thank you dbf
I was able to run a bat file using liquibase and pass parameters into it:
<property name="my_param_name" value="myValue"/>
<changeSet author="tobi" id="preMigration" >
<executeCommand executable="C:\projects\lbdemo\trunk\mybatfile.bat">
<arg value="Constant: ${my_param_name}"/>
</executeCommand>
</changeSet>
C:\projects\lbdemo\trunk\mybatfile.bat :
#echo off
if not exist "C:\Test\" mkdir C:\Test
set arg1=%1
(echo %arg1%) > C:\Test\EmptyFile.txt
mybatfile.bat will create an EmptyFile.txt and write the my_param_name value into it.
The documentation for the <sqlFile> custom refactoring tag says that the classpath will be searched for the file.
However I cannot get it to find my file, despite it being in the classpath.
The changeset element is:
<changeSet author="rebecca" id="9.1 - LoanIQ GoLive">
<comment>No rollback script exists</comment>
<sqlFile path="v9.1-loaniqgolive.sql"/>
</changeSet>
The ant task is:
<updateDatabase
changeLogFile="#{changelog}"
driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://${database.host}:${database.port};databaseName=${database.name}"
username="${database.user}"
password="${database.password}"
promptOnNonLocalDatabase="false"
dropFirst="false"
classpathref="liquibase.path"/>
The build reports that the liquibase path is:
[echo] The liquibase path = D:\Program Files\Jenkins\jobs\Deploy GMM\workspace\app\build\database;D:\Program Files\Jenkins\jobs\Deploy GMM\workspace\app\build\tools\liquibase\liquibase.jar;D:\Program Files\Jenkins\jobs\Deploy GMM\workspace\app\build\lib\sqljdbc.jar
I have confirmed that v9.1-loaniqgolive.sql is definitely in the path (1st element).
Yet I get this error:
D:\Program Files\Jenkins\jobs\Deploy GMM\workspace\app\build\ant\functions\db.xml:56: liquibase.exception.ChangeLogParseException: Invalid Migration File: <sqlfile path=v9.1-loaniqgolive.sql> -Unable to read file
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:132)
My config looks OK, but it doesn't work. How can I solve this or debug further?
One quick suggestion I have is to run Ant with -verbose and -debug command line parameters. This puts out a lot of logging but generally helps get you closer to the source of the problem.
I will try to create an equivalent Ant task against one of my dbs and respond with any updates.