Re : Integration with Dropwizard and JUnit
Re : Validate only with Spring integration
public class SpringLiquibase extends liquibase.integration.spring.SpringLiquibase {
private boolean validateOnly = false;
public boolean isValidateOnly() {
return validateOnly;
}
public void setValidateOnly(boolean validateOnly) {
this.validateOnly = validateOnly;
}
@Override
public void afterPropertiesSet() throws LiquibaseException {
ConfigurationProperty shouldRunProperty = LiquibaseConfiguration.getInstance()
.getProperty(GlobalConfiguration.class, GlobalConfiguration.SHOULD_RUN);
if (!shouldRunProperty.getValue(Boolean.class)) {
LogFactory.getLogger()
.info("Liquibase did not run because "
+ LiquibaseConfiguration.getInstance().describeValueLookupLogic(shouldRunProperty)
+ " was set to false");
return;
}
if (!shouldRun) {
LogFactory.getLogger().info("Liquibase did not run because 'shouldRun' " + "property was set to false on "
+ getBeanName() + " Liquibase Spring bean.");
return;
}
if (validateOnly) {
Connection c = null;
Liquibase liquibase = null;
try {
c = getDataSource().getConnection();
liquibase = createLiquibase(c);
if (liquibase.listUnrunChangeSets(new Contexts(contexts), new LabelExpression(getLabels()))
.size() > 0) {
throw new LiquibaseException("Unrun changes found in validate only mode");
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
Database database = null;
if (liquibase != null) {
database = liquibase.getDatabase();
}
if (database != null) {
database.close();
}
}
} else {
super.afterPropertiesSet();
}
}
}
Cannot get diff against Hibernate to work in ant
hibernate-core-4.2.7.SP1-redhat-3.jar
liquibase.jar (3.4.2)
liquibase-hibernate4.2-3.5.jar
liquibase-oracle-3.0.0.jar
As well as the other required jars of course.
My database:
<liquibase:database id="my-database"
driver="${liquibase.database.driver}"
url="${liquibase.database.url}"
user="${liquibase.database.username}"
password="${liquibase.database.password}" >
</liquibase:database>
liquibase.properties:
liquibase.database.username=emr
liquibase.database.password=xxxx
liquibase.database.driver=oracle.jdbc.driver.OracleDriver
liquibase.database.url=jdbc:oracle:thin:@(xxxx)
liquibase.persistence.unit=hibernate:ejb3:emrEJB?dialect=org.hibernate.dialect.OracleDialect
My ant diff target:
<target name="diff-against-hibernate">
<liquibase:diffDatabaseToChangeLog
databaseref="my-database"
classpathref="mypath.classpath"
diffTypes="tables,columns,views">
<referencedatabase url="${liquibase.persistence.unit}"/>
<txt outputfile="${change_control}/dbupdate/hibernate/${liquibase.hibernate.changelog.file}"/>
</liquibase:diffDatabaseToChangeLog>
</target>
I've tried a lot of different variations of the ant target and even tried the latest snapshot jar of liquibase. But every time I run I get the same error:
BUILD FAILED
C:\Production\jboss_emr_eap\g2\dbautomation.xml:111: JDBC driver is required.
Does the hibernate extension actually work with the latest liquibase jar? I swear I had this working in a previous version of liquibase but I seem to have misplaced that code.
If I run ant with the debug flag I get the full stack trace. (BTW I'm running ant inside eclipse):
at liquibase.integration.ant.type.DatabaseType.validateParameters(DatabaseType.java:133)
at liquibase.integration.ant.type.DatabaseType.createDatabase(DatabaseType.java:51)
at liquibase.integration.ant.BaseLiquibaseTask.createDatabaseFromType(BaseLiquibaseTask.java:100)
at liquibase.integration.ant.AbstractDatabaseDiffTask.getDiffResult(AbstractDatabaseDiffTask.java:24)
at liquibase.integration.ant.DiffDatabaseToChangeLogTask.executeWithLiquibaseClassloader(DiffDatabaseToChangeLogTask.java:44)
at liquibase.integration.ant.BaseLiquibaseTask.execute(BaseLiquibaseTask.java:81)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Re : Cannot get diff against Hibernate to work in ant
Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/
Re : Cannot get diff against Hibernate to work in ant
I looked at the source code for the line mentioned in the stack trace. It asks for the driver. Since this is a diff operation I'm not sure if the missing driver is for Oracle or for Hibernate. I was assuming the error was about Hibernate since I am supplying a driver for Oracle. But perhaps for some reason it doesn't see that variable.
Re : Cannot get diff against Hibernate to work in ant
Liquibase udeploy integration fails when loglevel=info
Re : Liquibase udeploy integration fails when loglevel=info
Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/
validCheckSum in formatted sql
--liquibase formatted sql logicalFilePath:test-file
--changeSet auth1:id1
--comment: ...
--validCheckSum: 7:99999
select '1'
Re : validCheckSum in formatted sql
Is it possible to simulate a while loop using Liquibase XML or other formats?
Here is an example of heavy DB migration (postgresql):
run the following statement in a separate transaction unless it returns zero
- WITH updated as (
- UPDATE some_table
- SET some_column = null
- WHERE id in (
- SELECT id
- FROM some_table
- WHERE some_column = 0
- LIMIT 50000
- )
- RETURNING 1
- )
- SELECT COUNT(*)
- FROM updated
Is it possible to perform such a loop (execute some statement in a separate transaction repeatedly unless it returns zero) using any of Liquibase migration formats, e.g. using XML includes or whatever?
Regards,
Alexey
Re : Is it possible to simulate a while loop using Liquibase XML or other formats?
Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/
Re : Is it possible to simulate a while loop using Liquibase XML or other formats?
Does Liquibase design allow to write a custom tag that results not in a fixed sequence of SQL statements, but to an interactive one, such as "run the following SQL repeatedly until it returns 0" or "run this SQL, if it failed run that one" ?
Re : Is it possible to simulate a while loop using Liquibase XML or other formats?
<executeCommand executable="./execphp" os="Linux">
<arg value="Add50SO.php"/>
</executeCommand>
Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/
Re : Cannot get diff against Hibernate to work in ant
- <target name="diff-against-hibernate">
<liquibase:diffDatabaseToChangeLog
databaseref="my-database"
classpathref="mypath.classpath"
diffTypes="tables,columns,views">
<referencedatabase driver="${liquibase.database.driver}" url="${liquibase.persistence.unit}" user="${liquibase.database.username}" password="${liquibase.database.password}"/>
<txt outputfile="${change_control}/dbupdate/hibernate/${liquibase.hibernate.changelog.file}"/>
</liquibase:diffDatabaseToChangeLog>
</target>
See if that helps.
Can Liquibase export blob data?
- java -jar liquibase.jar \
- ...
- --diffTypes="data" \
- generateChangeLog
Re : Cannot get diff against Hibernate to work in ant
diff-against-hibernate2:
[liquibase:diffDatabaseToChangeLog] Starting Liquibase.
dropping C:\Production\jboss_emr_eap\g2\buildLibs\hibernate-common-annotations-4.0.1.Final-redhat-2.jar from path as it doesn't exist
[liquibase:diffDatabaseToChangeLog] WARNING 4/12/16 1:39 PM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.springframework.beans.factory.support.BeanDefinitionRegistry is not in the classpath
BUILD FAILED
C:\Production\jboss_emr_eap\g2\dbautomation.xml:52: Unable to create Liquibase Database instance. Could not connect to the database.
at liquibase.integration.ant.type.DatabaseType.createDatabase(DatabaseType.java:78)
at liquibase.integration.ant.BaseLiquibaseTask.createDatabaseFromType(BaseLiquibaseTask.java:96)
at liquibase.integration.ant.AbstractDatabaseDiffTask.getDiffResult(AbstractDatabaseDiffTask.java:24)
at liquibase.integration.ant.DiffDatabaseToChangeLogTask.executeWithLiquibaseClassloader(DiffDatabaseToChangeLogTask.java:44)
at liquibase.integration.ant.BaseLiquibaseTask.execute(BaseLiquibaseTask.java:81)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Re : Cannot get diff against Hibernate to work in ant
I would double-check your JDBC URL and driver attributes on your <database> and <referencedatabase> elements and make sure it is correct and pointing to the right place.The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL.
Re : Cannot get diff against Hibernate to work in ant
- <target name="diff-against-hibernate2">
<liquibase:diffDatabaseToChangeLog
databaseref="my-database"
classpathref="mypath.classpath"
diffTypes="tables,columns,views">
<referencedatabase
driver="liquibase.ext.hibernate.database.connection.HibernateDriver"
url="${liquibase.persistence.unit}"
user="${liquibase.database.username}"
password="${liquibase.database.password}"/>
<txt outputfile="hibernate-diff-test.xml"/>
</liquibase:diffDatabaseToChangeLog>
</target>
- [liquibase:diffDatabaseToChangeLog] WARNING 4/13/16 11:15 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.springframework.beans.factory.support.BeanDefinitionRegistry is not in the classpath
[liquibase:diffDatabaseToChangeLog] Reading hibernate configuration hibernate:ejb3:emrEJB?dialect=org.hibernate.dialect.OracleDialect
BUILD FAILED
C:\Production\jboss_emr_eap\g2\dbautomation.xml:52: java.lang.NoClassDefFoundError: javax/persistence/PersistenceException
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Caused by: java.lang.NoClassDefFoundError: javax/persistence/PersistenceException
at liquibase.ext.hibernate.database.HibernateEjb3Database.buildConfigurationFromFile(HibernateEjb3Database.java:76)
at liquibase.ext.hibernate.database.HibernateEjb3Database.buildConfiguration(HibernateEjb3Database.java:28)
at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:44)
at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:123)
at liquibase.integration.ant.type.DatabaseType.createDatabase(DatabaseType.java:82)
at liquibase.integration.ant.BaseLiquibaseTask.createDatabaseFromType(BaseLiquibaseTask.java:96)
at liquibase.integration.ant.AbstractDatabaseDiffTask.getDiffResult(AbstractDatabaseDiffTask.java:24)
at liquibase.integration.ant.DiffDatabaseToChangeLogTask.executeWithLiquibaseClassloader(DiffDatabaseToChangeLogTask.java:44)
at liquibase.integration.ant.BaseLiquibaseTask.execute(BaseLiquibaseTask.java:81)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
... 10 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.PersistenceException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 24 more
- <target name="generate-database-dll">
<liquibase:generateChangeLog databaseref="my-database"
classpathref="mypath.classpath" >
<liquibase:xml outputfile="/path/to/output/changelog.xml" encoding="UTF-8"/>
</liquibase:generateChangeLog>
</target>
Inserting the content of an XML file into a DB Table in a change-set
We have a table called XMLData
with the column Data
, type XML
.
We want to insert the contents of an XML file (e.g. Customer.XML
) that is located in a folder in the same directory with the change-log file. The XML file is very large. While it is technically possible to copy and paste it's contents into the change log file, that is not an option for us.
It would be ideal if there was a way to reference an external file in a changeset.
I'm trying to determine if Liquibase is appropriate for this task, and what the best way to do it within liquibase is.
Here is what I tried:
<changeSet author="Jack" id="2016123456">
<insert schemaName="MySchema" tableName="XMLData">
<column name="Data" valueClobFile="Data\Customer.xml"/>
</insert>
</changeSet>
I get the following error:
Unexpected error running Liquibase: com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting date and/or time from character string.
The error does not make sense to me because the data being inserted in an XML file. I get the same error even when the file content is empty.
Any suggestions or advice?
Thanks in advance.