Liquibase Update Failed - liquibase

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

Related

incrementBy is not allowed on mysql, liquibase, quarkus

I try to use liquibase with mysql in my quarkus application, this is the error I'm getting:
incrementBy is not allowed on mysql, db/changeLog.xml::added-autoincrement-to-id::VO
<createTable tableName="my_users">
<column name="id" type="bigint" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
</createTable>
<changeSet id="added-autoincrement-to-id" author="VO">
<addAutoIncrement
columnDataType="bigint"
columnName="id"
incrementBy="1"
startWith="1"
tableName="my_users"/>
</changeSet>
pom.xml
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-liquibase</artifactId>
</dependency>
using the latest mysql version, served by docker.

Why is liquibase trying to recreate the table DATABASECHANGELOG

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

How to use one ChangeLog inside another in 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.

Liquibase Change Log Parameter error: ERROR: syntax error at or near "$"

I have a changelog:
<sql>
DROP ROLE IF EXISTS tenant_access;
CREATE ROLE tenant_access
NOSUPERUSER INHERIT NOCREATEDB
NOCREATEROLE NOREPLICATION;
GRANT ALL ON DATABASE ${db_name} TO tenant_access;
</sql>
And in the liquibase.properties I have:
changeLogFile=src/main/resources/db/changelog/db.changelog-master.xml
url=jdbc:postgresql://localhost:5432/postgres
username=postgres
password=mysecretpassword
parameter.db_name=postgres
When I run mvn liquibase:update, there is an error:
[ERROR] Change Set src/main/resources/db/changelog/changelog-1-1-create-group-role-tenant-access.xml::create_tenant_access_group_role::failed.
Error: ERROR: syntax error at or near "$"
Could you let me know what could be wrong?
Thank you!
If you need to have your properties in property file, then it should be parameter.db_name=postgres, not parameters.db_name=postgres.
Or you can try to move properties to changelog file, into <property> tag.
Here are the liquibase docs.
Here's the example from these docs.
<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-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<property name="clob.type" value="clob" dbms="oracle"/>
<property name="clob.type" value="longtext" dbms="mysql"/>
<changeSet id="1" author="joe">
<createTable tableName="${table.name}">
<column name="id" type="int"/>
<column name="${column1.name}" type="${clob.type}"/>
<column name="${column2.name}" type="int"/>
</createTable>
</changeSet>
</databaseChangeLog>
I do not know why, but if I specify in my application.properties: liquibase.parameters.db_name: postgres, this works.
using ' I think should help
GRANT ALL ON DATABASE '${db_name}' TO tenant_access;

Liquibase: check if a property was set

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