Liquibase配置说明
===========================

以Spring Boot集成Liquibase为例。

a. 在项目中引入Liquibase的依赖。

   在pom.xml 中增加如下声明：

   .. code:: PROGRAMLISTING

          <dependency>
              <groupId>org.liquibase</groupId>
              <artifactId>liquibase-core</artifactId>
          </dependency>

b. 配置changelog文件。

   在classpath:/db/changelog中声明一个db.changelog-master.xml文件：

   .. code:: PROGRAMLISTING

          <?xml version="1.0" encoding="utf-8"?>
          <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-3.8.xsd">

              <include file="classpath:db/changelog/init-table.xml"
                  relativeToChangelogFile="false" />
              <include file="classpath:db/changelog/init-data.xml"
                  relativeToChangelogFile="false" />
          </databaseChangeLog>

   在classpath:/db/changelog中声明一个init-table.xml文件：

   .. code:: PROGRAMLISTING

          <?xml version="1.0" encoding="UTF-8"?>
          <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-3.8.xsd">

              <changeSet id="1" author="test">
                  <sql>
                      create table person(
                      id serial primary key,
                      name text,
                      date date,
                      sex bool,
                      blob blob,
                      clob clob
                      );
                  </sql>
              </changeSet>
          </databaseChangeLog>

   在classpath:/db/changelog中声明一个init-data.xml文件：

   .. code:: PROGRAMLISTING

          <?xml version="1.0" encoding="utf-8"?>
          <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-3.8.xsd">

              <changeSet id="2" author="test">
                  <insert tableName="person">
                      <column name="name" value="init"></column>
                      <column name="date" value="2010-01-01"></column>
                      <column name="sex" value="false"></column>
                      <column name="blob" value="blob"></column>
                      <column name="clob" value="clob"></column>
                  </insert>
              </changeSet>
          </databaseChangeLog>

c. 在application.properties中指定要加载的changelog文件：

   .. code:: PROGRAMLISTING

          spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml

d. 在启动项目时，会进行自动加载。


