Quantcast
Channel: Liquibase Forums
Viewing all 1169 articles
Browse latest View live

Re : Integration with Dropwizard and JUnit


Re : Validate only with Spring integration

$
0
0
Thanks for the pointer. I had a look at how that works and implemented a solution based on it. I've sent a pull request (https://github.com/liquibase/liquibase/pull/562) but I'm using a subclassing approach in the mean time:


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

$
0
0
I am using these jars:
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

$
0
0
You just need to make sure that the Oracle JDBC driver jar is included in your list of jars. I am not sure what is in liquibase-oracle-3.0.0.jar, but it seems like that is the problem.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Re : Cannot get diff against Hibernate to work in ant

$
0
0
Thanks for the suggestion.  I should have mentioned that I am including ojdbc6.jar, which does include the Oracle driver.  I also removed liquibase-oracle-3.0.0.jar, but still the same error.

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

$
0
0
Perhaps someone could post a complete working example of the ant script and properties required to get this to work.  I've tried dozens of variations of jar files, properties, and attributes for the diffDatabaseToChangeLog task.  But I always get exactly the same error about the JDBC driver being required.

Liquibase udeploy integration fails when loglevel=info

$
0
0
Hi , Am working for udeploy and i have created a plugin to call the liquibase commands from udeploy. So far, it was working fine till i add the loglevel==info to invoke the Liquibase command.After adding loglevel==info, Liquibase command hangs for more hours and havent got any output.

What is happening from Liquibase when the loglevel is introduced.

My code is like this.

commandLine="""
${javaHome}${fileSep}bin${fileSep}java -cp ${liquidClasspath}
liquibase.integration.commandline.Main 
 --driver=${driver} 
--username=${username}
--password=${password}
--url=${url} 
 --changeLogFile=${changelog}
--logLevel=info
${command} 
"""
println "debug----"
println commandLine 
println "debug----"
if(parameter){
   commandLine=commandLine+" "+parameter
}

def proc=commandLine.execute()
proc.waitFor()


Am stuck on this and unable to take it forward.Please help in this regard.

I am using Liquibase 3.1.1 version

Re : Liquibase udeploy integration fails when loglevel=info


validCheckSum in formatted sql

$
0
0
Is it possible to place a validCheckSum comment in a liquibase formatted sql.  I tried the following and it did not work.  Is there a different way to register a secondary validCheckSum value?

--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?

$
0
0
Hello

Here is an example of heavy DB migration (postgresql):
run the following statement in a separate transaction unless it returns zero
  1. WITH updated as (
  2.       UPDATE some_table
  3.       SET some_column = null
  4.       WHERE id in (
  5.             SELECT id
  6.             FROM some_table
  7.             WHERE some_column = 0
  8.             LIMIT 50000
  9.       )
  10.       RETURNING 1
  11. )
  12. SELECT COUNT(*)
  13. FROM updated
Updating not so many rows in each step saves the live database from suffering from long transactions and locked rows, and looping guarantees all rows to be 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?

$
0
0
This would need to be done inside a <sql> change tag or a custom change tag you write yourself. Liquibase itself does not have anything built-in like this.

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?

$
0
0
Unfortunately it is not possible to do it in SQL in PostgreSQL, at least not using JDBC (it is only possible to write it in psql scripting language in some ugly way).

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?

$
0
0
When you write a custom tag, you can do pretty much anything you want. We have written a custom <sqlplus> tag for Oracle that allows you to run the sqlplus command line tool, which allows for the kinds of things you are talking about. Doing something similar for the psql scripting language wouldn't be too difficult. There is also the <executeCommand> change tag, which isn't well documented, but might work for you. It looks something like this:

<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

$
0
0
Your <referencedatabase> element is not fully filled out. That element is the same type as a <database> element and takes the same attributes. Something like this:

  1. <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?

$
0
0
Hi

Is Liquibase supports blob data type when generating changelog?

  1. java -jar liquibase.jar \
  2.     ...
  3.     --diffTypes="data" \
  4.     generateChangeLog

Re : Cannot get diff against Hibernate to work in ant

$
0
0
Thanks.  That gets past the JDBC driver issue but now I have this:

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

$
0
0
It looks like the Liquibase cannot connect to the database. It is trying to call driver.connect()on the given JDBC URL and driver and that method is returning null. According to the JDBC Javadoc:
The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL.
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.

Re : Cannot get diff against Hibernate to work in ant

$
0
0
Thanks.  I changed the jdbc driver for the referencedatabase only to liquibase.ext.hibernate.database.connection.HibernateDriver based on something I read in one of the forum posts here.  So my target looks like this:
  1.     <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>

Note that the user and password for the referencedatabase are the same as for the target database.  That results in a different error:

  1. [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

I don't know why it cannot find PersistenceException.  It is on the path given to the target.  BTW other liquibase operations that are not in the hibernate extension work.  For instance:

  1. <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>   
This works perfectly.

Inserting the content of an XML file into a DB Table in a change-set

$
0
0

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.

Viewing all 1169 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>