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
Related
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;
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.
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