首页 > 解决方案 > Liquibase 差异功能

问题描述

..所以我正在热身 Liquibase 并努力让liquibase diff功能正常工作。我希望我可以使用这个论坛来获得一些帮助。

问题描述

我用 changeset1 和 changeset2 更新了我的 Dev DB,而 Prod DB 只用 changeset1 更新了。使用 SQL 开发人员 UI,我可以看到在 Dev 和 Prod 上创建的 changeset1 对应的表,而 changeset2 对应的表不在 Prod DB 中。到目前为止,这是在预期的线路上。

但是,当我在 Prod 上执行liquibase diff并引用 Dev DB 时,我希望看到差异(changeset2)。但是,我没有看到 Liquibase 输出中列出的更改 - 因此这篇文章。我哪里会出错?

请注意,我使用的是 dockerised 的 Oracle 实例,并且有 2 个 docker-db 实例分别模拟 Dev 和 Prod 环境。

Maven pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.jenkov</groupId>
  <artifactId>hello-world</artifactId>
  <version>1.0.0</version>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.liquibase</groupId>
          <artifactId>liquibase-maven-plugin</artifactId>
          <version>3.8.7</version>
          <dependencies>
            <dependency>
              <groupId>com.oracle</groupId>
              <artifactId>ojdbc14</artifactId>
              <version>10.2.0.4.0</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
    <profile>
      <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.8.7</version>
            <configuration>
              <dropFirst>false</dropFirst>
              <propertyFile>src/main/resources/liquibase/liquibase-dev.properties</propertyFile>
            </configuration>
            <executions>
              <execution>
                <phase>compile</phase>
                <goals>
                  <goal>update</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M4</version>
            <configuration>
              <skipTests>false</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>prod</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.8.7</version>
            <configuration>
              <dropFirst>false</dropFirst>
              <propertyFile>src/main/resources/liquibase/liquibase-prod.properties</propertyFile>
            </configuration>
            <executions>
              <execution>
                <phase>compile</phase>
                <goals>
                  <goal>update</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M4</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

liquibase-dev.properties

changeLogFile: src\/main\/resources\/liquibase\/dbchangelog.xml
url: jdbc:oracle:thin:@localhost:1521/xe
username: system
password:
verbose: true
referenceUrl: jdbc:oracle:thin:@localhost:1521/xe
referenceUsername: system
referencePassword:

liquibase-prod.properties

changeLogFile: src\/main\/resources\/liquibase\/dbchangelog.xml
url: jdbc:oracle:thin:@localhost:1523/xe
username: system
password:
verbose: true
referenceUrl: jdbc:oracle:thin:@localhost:1521/xe
referenceUsername: system
referencePassword:

dbchangelog.xml

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" 
    xmlns:pro="http://www.liquibase.org/xml/ns/pro" 
    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="bob">
        <createTable tableName="department">
            <column name="id" type="int">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="active" type="boolean" defaultValueBoolean="true"/>
        </createTable>
    </changeSet>
        <changeSet id="2" author="bob">
        <createTable tableName="department2">
            <column name="id" type="int">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="active" type="boolean" defaultValueBoolean="true"/>
        </createTable>
    </changeSet>
</databaseChangeLog>

执行的命令

mvn liquibase:diff -Pprod

Liquibase 输出

$ mvn liquibase:diff -Pprod
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.jenkov:hello-world >-----------------------
[INFO] Building hello-world 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.8.7:diff (default-cli) @ hello-world ---
[INFO] ------------------------------------------------------------------------
[INFO] there are no resolved artifacts for the Maven project.
[INFO] Parsing Liquibase Properties File
[INFO]   File: src/main/resources/liquibase/liquibase-prod.properties
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO]
[INFO] Liquibase Community 3.8.7 by Datical
[INFO] Starting Liquibase at Fri, 20 Mar 2020 23:35:03 NZDT (version 3.8.7 #55 built at Mon Feb 24 03:04:51 UTC 2020)
[INFO] Parsing Liquibase Properties File src/main/resources/liquibase/liquibase-prod.properties for changeLog parameters
[INFO] Executing on Database: jdbc:oracle:thin:@localhost:1523/xe
[INFO] there are no resolved artifacts for the Maven project.
[INFO] there are no resolved artifacts for the Maven project.
[INFO] Performing Diff on database SYSTEM @ jdbc:oracle:thin:@localhost:1523/xe (Default Schema: SYSTEM)

Diff Results:
Reference Database: SYSTEM @ jdbc:oracle:thin:@localhost:1521/xe (Default Schema: SYSTEM)
Comparison Database: SYSTEM @ jdbc:oracle:thin:@localhost:1523/xe (Default Schema: SYSTEM)
Compared Schemas: SYSTEM
Product Name: EQUAL
Product Version: EQUAL
Missing Catalog(s): NONE
Unexpected Catalog(s): NONE
Changed Catalog(s): NONE
Missing Column(s): NONE
Unexpected Column(s): NONE
Changed Column(s): NONE
Missing Foreign Key(s): NONE
Unexpected Foreign Key(s): NONE
Changed Foreign Key(s): NONE
Missing Index(s): NONE
Unexpected Index(s): NONE
Changed Index(s): NONE
Missing Primary Key(s): NONE
Unexpected Primary Key(s): NONE
Changed Primary Key(s): NONE
Missing Sequence(s): NONE
Unexpected Sequence(s): NONE
Changed Sequence(s): NONE
Missing Table(s): NONE
Unexpected Table(s): NONE
Changed Table(s): NONE
Missing Unique Constraint(s): NONE
Unexpected Unique Constraint(s): NONE
Changed Unique Constraint(s): NONE
Missing View(s): NONE
Unexpected View(s): NONE
Changed View(s): NONE
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.087 s
[INFO] Finished at: 2020-03-20T23:35:03+13:00
[INFO] ------------------------------------------------------------------------

标签: databaseoraclemavendevopsliquibase

解决方案


推荐阅读