9
votes

I'm new to liquibase and I want to use it on an database in production. It's a small application, but instead of creating schema by hand I would like to use something more professional like liquibase.

What I plan to do is to make a changelog between the current schema in production and the new schema ready for the new application. I've followed many tutorials but there is still something missing. The output changelog.xml always imports all the schema and doesn't make the difference with the existing. I saw that liquibase had to create the table DATABASECHANGELOG but I couldn't see them on my computer.

What I did :

  • dump of the current db in production and import on dev computer
  • from core project added liquibase.properties and launched the following command : mvn clean resources:resources liquibase:generateChangeLog
  • this generated a master.xml with all the schema, but didn't create the tables DATABASECHANGELOG in DB (the table DATABASECHANGELOGLOCK was created when commenting outputChangeLogFile, and the LOCKED value is 0)
  • created manually the DATABASECHANGELOG from http://www.liquibase.org/databases.html
  • rerun the command mvn liquibase:generateChangeLog. Still nothing

pom.xml :

<dependencies>
    ...
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
        <version>3.5.3</version>
    </dependency>
    <dependency>
        <groupId>org.yaml</groupId>
        <artifactId>snakeyaml</artifactId>
        <version>1.17</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
</dependencies>

 <!-- edited build after 1st comment. Still got the problem -->
<build>
    <plugins>
        <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.version}</version>
            <configuration>
                <promptOnNonLocalDatabase>true</promptOnNonLocalDatabase>
                <changeLogFile>${project.build.directory}/classes/changelog/db.changelog-master.xml</changeLogFile>
                <propertyFile>src/main/resources/liquibase.properties</propertyFile>
            </configuration>
        </plugin>
    </plugins>
</build>

<!--- old section build, left for history purpose --->
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>${liquibase.version}</version>
                <configuration>
                    <promptOnNonLocalDatabase>true</promptOnNonLocalDatabase>
                    <changeLogFile>${project.build.directory}/classes/changelog/db.changelog-master.xml</changeLogFile>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

liquibase.properties :

url=jdbc:mysql://localhost:3306/my_db
username=user
password=pass
driver=com.mysql.jdbc.Driver
outputChangeLogFile=src/main/resources/liquibase/master.xml

NB : commenting outputChangeLogFile made liquibase create the table DATABASECHANGELOGLOCK, but only this one.

maven output :

[INFO] ------------------------------------------------------------------------
[INFO] Building -CORE 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.5.3:generateChangeLog (default-cli) @ EDI-CORE ---
[INFO] ------------------------------------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO]   File: src/main/resources/liquibase.properties
[INFO]   'classpath' in properties file is not being used by this task.
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:mysql://localhost:3306/my_db
[INFO] Generating Change Log from database root@localhost @ jdbc:mysql://localhost:3306/my_db (Default Schema: edi)
INFO 17/01/17 15:01: liquibase: src\main\resources\liquibase\master.xml exists, appending
WARNING 17/01/17 15:01: liquibase: MySQL does not support a timestamp precision of '19' - resetting to the maximum of '6'
WARNING 17/01/17 15:01: liquibase: MySQL does not support a timestamp precision of '19' - resetting to the maximum of '6'
WARNING 17/01/17 15:01: liquibase: MySQL does not support a timestamp precision of '19' - resetting to the maximum of '6'
[INFO] Output written to Change Log file, src/main/resources/liquibase/master.xml
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
6
You are using <pluginManagement>, see the linked question for the explanation of behaviour and fix.Tunaki
I have changed this part right now (see the edited pom.xml), but the problem is still there : no table has been createdbelkor
Liquibase provides tool to generate schema automatically from current working DB in your case it's production. You just have to point tool to your DB and it'll create schema for you. stackoverflow.com/questions/12449824/… check this solution.Mayur

6 Answers

1
votes

As far as I know (I'm new too), tables DATABASECHAGELOG and DATABASECHANGELOGLOCK are created by update option: mvn liquibase:update

0
votes

It does not support a timestamp precision of '19' is about your Data Type in MySQL

MySQL does not support your Data Type column for your Entity.

0
votes

Since you are specify a outputChangeLogFile in your properties file Liquibase is trying to create it (via liquibase:generateChangeLog) for your based on your specified connection. Try to use changeLogFile in your liquibase.prperties instead:

url=jdbc:mysql://localhost:3306/my_db
username=user
password=pass
driver=com.mysql.jdbc.Driver
changeLogFile=src/main/resources/liquibase/master.xml
0
votes

Liquibase works via changelog and changesets. It first tries to locate master changelog file and the changesets which are mentioned in that file are executed in order. If you have specified any DB connection then Liquibase will use that credentials and if not then you can specify the liquibase DB credentails.

Please go the spring boot doc for liquibase for the list of properties - https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#data-migration-properties

Sample liquibase property

  liquibase:
    change-log: classpath:db/changelog/db.changelog-master.xml
    enabled: true
    drop-first: false
    liquibase-tablespace: 
    liquibase-schema: 
    default-schema: 
0
votes

Your current question appears to be:

[When I ran]

mvn clean resources:resources liquibase:generateChangeLog

[why does] liquibase not generate table DATABASECHANGELOG?

The answer to this is that the DATABASECHANGELOG table is used by Liquibase to track which changelogs have been applied to the current table, so it is only created during update and similar commands. The command generateChangeLog does not run any changelogs, so there is no need to create any entries in DATABASECHANGELOG.

I suspect this may not be your underlying question though. Why do you care whether Liquibase creates DATABASECHANGELOG or not?

Has this question been edited several times? Lots of the answers here don't address the question as it currently stands.

I wonder if your real question is more like "how do I use Liquibase to manage schema changes when there is already some existing schema in place"? If so, the tutorial page "How to set up Liquibase with an Existing Project and Multiple Environments" goes some way towards answering that.

GL!

-4
votes

Review carefully if your files are well indented and if you write tags like changeSet correctly