Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Obtaining the SQL statements, representing the diff between two databases, is a two step operation:</p> <ol> <li>Generate the XML "diff" changelog </li> <li>Generate SQL statements</li> </ol> <h1>Example</h1> <p>This example requires a <strong>liquibase.properties</strong> file (simplifies the <a href="http://www.liquibase.org/manual/command_line" rel="nofollow noreferrer">command-line</a> parameters):</p> <pre><code>classpath=/path/to/jdbc/jdbc.jar driver=org.Driver url=jdbc:db_url1 username=user1 password=pass1 referenceUrl=jdbc:db_url2 referenceUsername=user2 referencePassword=pass2 changeLogFile=diff.xml </code></pre> <p>Now run the following commands to create the SQL statements:</p> <pre class="lang-sh prettyprint-override"><code>liquibase diffChangeLog liquibase updateSQL &gt; update.sql </code></pre> <p>A nice feature of liquibase is that it can also generate the rollback SQL:</p> <pre class="lang-sh prettyprint-override"><code>liquibase futureRollbackSQL &gt; rollback.sql </code></pre> <h1>Update</h1> <p>Liquibase does not generate a data diff between databases, only the schema. However, it is possible to dump database data as a series of changesets:</p> <pre class="lang-sh prettyprint-override"><code>liquibase --changeLogFile=data.xml --diffTypes=data generateChangeLog </code></pre> <p>One can use the <strong>data.xml</strong> file to migrate data contained in new tables.</p> <h1>Update 2:</h1> <p>Also possible to generate liquibase changesets using groovy.</p> <pre class="lang-java prettyprint-override"><code>import groovy.sql.Sql import groovy.xml.MarkupBuilder // // DB connection // this.class.classLoader.rootLoader.addURL(new URL("file:///home/path/to/h2-1.3.162.jar")) def sql = Sql.newInstance("jdbc:h2:db/db1","user","pass","org.h2.Driver") // // Generate liquibase changeset // def author = "generated" def id = 1 new File("extract.xml").withWriter { writer -&gt; def xml = new MarkupBuilder(writer); xml.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:author, id:id++) { sql.eachRow("select * from employee") { row -&gt; insert(tableName:"exmployee") { column(name:"empno", valueNumeric:row.empno) column(name:"name", value:row.name) column(name:"job", value:row.job) column(name:"hiredate", value:row.hiredate) column(name:"salary", valueNumeric:row.salary) } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload