We are using LB 3.5. Below is the master changelog
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<!-- v13.0.00 -->
<include context="v13_0_00_03" file="changelog-v13.0.00.03.xml" relativeToChangelogFile="true"/>
<include context="v13_0_00_04" file="changelog-v13.0.00.04.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Now in changelog-v13.0.00.03.xml we have these changeSets:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet id="CT-39_1" author="auth1" failOnError="false" runOnChange="false" labels="DDL">
<sqlFile encoding="utf8" endDelimiter="\nGO" path="../scripts/ddl/ddl.sql" relativeToChangelogFile="true" />
</changeSet>
<changeSet id="CT-2" author="auth2" runOnChange="false" labels="TRIGPROC">
<preConditions onFail="CONTINUE">
<changeSetExecuted id="CT-39_1" author="auth1" />
</preConditions>
<sqlFile encoding="utf8" endDelimiter="\nGO" path="../scripts/trigprocs/sp_ins1.sql" relativeToChangelogFile="true"/>
</changeSet>
<changeSet id="CT-18" author="auth3" runOnChange="false" labels="TRIGPROC">
<sqlFile encoding="utf8" endDelimiter="\nGO" path="../scripts/trigprocs/sp_ins2.sql"
relativeToChangelogFile="true"/>
</changeSet>
<changeSet id="CT-2228" author="auth4" runOnChange="false" labels="CONFIG">
<sqlFile encoding="utf8" endDelimiter="\nGO" path="../scripts/config/insert_rec.sql" relativeToChangelogFile="true"/>
</changeSet>
The following command works fine as I expect to see SQL file of v13.0.00.03 and labeled as CONFIG:
liquibase --contexts=v13_0_00_03 --labels=CONFIG updateSQL
But this command won't work
liquibase --contexts=v13_0_00_03 --labels="CONFIG, DDL" updateSQL
It only generates SQL for CONFIG and not DDL. I tried "CONFIG or DDL", no luck.
Another issue is that, if I change the 'labels' attribute in changeSets to 'context', LB doesn't generate anything using --contexts="v13_0_00_03, CONFIG".
Are these bugs or have I missed anything here?
The only possibility that I can think of is that the DDL changes have already been applied. You have the changeset that is labeled DDL as runOnChange=false, so even if the file has changed it will not re-run.
Related
I created a liquibase.properties as follows
driver: net.snowflake.client.jdbc.SnowflakeDriver
classpath: ./liquibase-snowflake-1.0.jar
url: jdbc:snowflake://....us-east-1.snowflakecomputing.com/?db=...&warehouse=...&schema=LIQUIBASE&role=SYSADMIN
username: ...
password: ...
changeLogFile: mySnowflakeChangeLog.xml
Initially running liquibase while the file mySnowflakeChangeLog.xml did not exist worked up to creating the liquibase tables within the LIQUIBASE schema (which I had to create first).
Now, if I supply a simple changelog file mySnowflakeChangeLog.xml (see below), the update fails when trying to re-create the underlying liquibase table:
"Object 'DATABASECHANGELOG' already exists"
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="eric" id="changelog-1.0">
<createTable tableName="TablesAndTables">
<column name="COLUMN1" type="TEXT">
<constraints nullable="true" primaryKey="false" unique="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>
Am I missing something? (I suppose I am...)
I had specified a default schema of LIQUIBASE but I had not informed liquibase where to retrieve its tables.
This is done through the parameter liquibaseSchemaName so all I had to do was to add the following line in my liquibase.properties file
liquibaseSchemaName: LIQUIBASE
I have two changeLog which has changesets to create two tables .
The changelog having changeset to create person
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="1" author="nvoxland">
<createTable tableName="person">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="firstname" type="varchar(50)" />
<column name="lastname" type="varchar(50)">
<constraints nullable="false" />
</column>
<column name="state" type="char(2)" />
<column name="district" type="char(2)" />
<column name="city" type="char(2)" />
</createTable>
</changeSet>
</databaseChangeLog>
and the changelog to create passport
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="2" author="nvoxland">
<createTable tableName="passport">
<column name="passportNo" type="int">
<constraints primaryKey="true" nullable="false" />
</column>
</createTable>
</changeSet>
</databaseChangeLog>
I want to create a new changeset in a separate changelog which can use the above two changelog and add a foreignkey constraint between person and passport.
Something like this
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="3" author="nvoxland">
import changeset 1 & 2
add foreign-key between person & passport
</changeSet>
</databaseChangeLog>
Is this possible using Liquibase? Please suggest the possible ways.
If I get your question right, you can use master-changelog.xml file and specify all your changelog files there.
Your master-changelog may look like this:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="changelog/changelog_file_1.xml" relativeToChangelogFile="true"/>
<include file="changelog/changelog_file_2.xml" relativeToChangelogFile="true"/>
<include file="changelog/changelog_file_3.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
changelog files will be executed in the provided order, so the third changelog will already have all the needed data available.
So in your changelog_file_3.xml you'll have a changeSet with <addForeignKeyConstraint>.
By the way, you don't need to create separate changelog for each changeset.
I have directory structure for migrations as follow:
db1:
latest/ (triggers,functions,procedures)
tables/
v000/master.xml
update.xml
db1/update.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<include file="v000/master.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
db2: (try to include db1/update.xml) schema here , as I need to extend/add to db1 schema )
update.xml
db2/update.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<include file="../db1/update.xml" />
</databaseChangeLog>
db1> liquibase --changeLogFile=update.xml update , successful
but
db2 > liquibase --changeLogFile=update.xml validate
show validation errors for tables included from db1/v000/master.xml
<include file="tables/12_createTable_audiences.xml" />
Error Reading Migration File:tables/12_createTable_audiences.xml .....
if I fix the error by following changes (for each table: in db1/v000/mater.xml)
<include file="../tables/12_createTable_audiences.xml" relativeToChangelogFile="true"/>
db2 > liquibase --changeLogFile=update.xml validate/update works fine
but
db2 > liquibase --changeLogFile=update.xml dbDocs ~/docs/db1
fails on table 12_createTable_audiences.xml
Does any one know how to fix these (path issues) ? Why update and dbDoc commands behave differently for same paths ?
thanks for your kind support.
Instead of using relativeToChangelogFile attribute try to specify the path in include file from the root. Something like
<iuclude file = "./Update/db1/update.xml" />
I am using the following the quickstart on liquibase
My xml Code:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<changeSet id="1" author="bob">
<createTable tableName="department">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="active" type="boolean" defaultValueBoolean="true"/>
</createTable>
</changeSet>
</databaseChangeLog>
When I run Liquibase via command line using "update" command .Liquibase tells me this
INFO 8/31/12 9:17 AM:liquibase: Successfully released change log lock
Liquibase Update Failed: Content is not allowed in prolog.
SEVERE 8/31/12 9:17 AM:liquibase: Content is not allowed in prolog.
liquibase.exception.ChangeLogParseException: Error parsing line 1 column 1 of dat
abase.xml: Content is not allowed in prolog.
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXP
arser.java:106)
at liquibase.Liquibase.update(Liquibase.java:107)
My update command is
liquibase --driver=com.mysql.jdbc.Driver --classpath=mysql-connector-java-5.1.6.jar --changeLogFile=database.xml --url="jdbc:mysql://localhost:3306/sample" --username=root --password=password update
How do I do this?
It's probably because there are several hidden characters (such as BOM, google XML BOM for more information) at the beginning of your XML file.
This link shows how to remove BOM.
If you are using Windows, XVI32 (a free hex editor) would work for you.
Refer to Liquibase JIRA issue
This problem is related to schema definitions...try with schema definition from attachment example of the given link
I could not find a way to check in a precondition element if a custom property is set.
What I found out about this issue so far is here.
As the ticket comment indicates, extending CustomPrecondition will not help without modifying the API. Is there another way?
The documentation describes a changeLogPropertyDefined precondition.
The following example worked fine for me:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<changeSet author="mark (generated)" id="mark-1">
<preConditions onFail="HALT">
<changeLogPropertyDefined property="testing" value="1"/>
</preConditions>
<createTable tableName="TEST001">
<column name="ID" type="VARCHAR(10)">
<constraints nullable="false"/>
</column>
<column name="X" type="VARCHAR(9)">
<constraints nullable="false"/>
</column>
<column name="Y" type="DECIMAL(7,2)"/>
<column name="Z" type="DECIMAL(7,2)"/>
</createTable>
</changeSet>
</databaseChangeLog>
I run liquibase from Maven. The testing property can be set from the command line as follows:
mvn -Dtesting=1 compile