9

I actually use Liquibase on windows in command lines, and I try to create an sql script that represent the diff between two databases. Unfortunatly I only get xml file in return. Can you help me ?

My command line :

liquidbase.bat 
   --driver=com.mysql.jdbc.Driver 
   --url=jdbc:mysql://localhost:3306/base1 
   --username=root 
   diffChangeLog 
   --referenceUrl=jdbc:mysql://localhost:3306/base2 
   --referenceUsername=root 
> test.sql

I've seen this similar question in an other forum but he didn't got a good answer (http://forum.liquibase.org/topic/convert-changelog-xml-file-into-sql-file). I've also seen some parameters for getting sql file from updateSQL cmd, but never for a diffChangeLog.

Example of the xml feedback :

<?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="user (generated)" id="1370443156612-1">
        <createTable tableName="test">
            <column name="a" type="INT"/>
        </createTable>
    </changeSet>
    <changeSet author="user (generated)" id="1370443156612-2">
        <addColumn tableName="articles">
            <column name="date_debut" type="TEXT">
                <constraints nullable="false"/>
            </column>
        </addColumn>
    </changeSet>

Thanks by advance.

1

2 Answers 2

8

The diff command only provides a textual overview of the differences.

In order to get an SQL of the difference of a new (dev) and old database:

  1. Use diffChangeLog to (temporarily perhaps) update your changelog by comparing two databases

  2. Use updateSQL against the out-of-date database to show the sql commands that would be run to bring it up to date. Note the printed SQL will also contain commands needed by liquibase for administration.

You can then commit the new changelog with your code if the new/dev database is what you expect. Use changelogSync to make the new/dev database thinks it's been updated by liquibase.

Sign up to request clarification or add additional context in comments.

Comments

0

You're running the diffChangeLog command, I think you want the diff command? See Output Modes in the manual.

liquibase.bat 
  --driver=com.mysql.jdbc.Driver 
  --url=jdbc:mysql://localhost:3306/base1 
  --username=root 
  --referenceUrl=jdbc:mysql://localhost:3306/base2 
  --referenceUsername=root 
  diff
    > test.sql

1 Comment

This is not true. the process is not so direct. No SQL compliant code is generated, only a textual overview like @Ian Rogers says.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.