【问题标题】:How to rollback your DB to a specific changeset ID in Spring Boot using liquibase?如何使用 liquibase 将您的数据库回滚到 Spring Boot 中的特定变更集 ID?
【发布时间】:2019-05-07 22:03:19
【问题描述】:

我有一个基于Spring Boot 的基本项目,它使用DDLDML 脚本来使用Liquibase 数据库版本控制填充我的H2 独立数据库。

正在创建表,并且数据也在其中填充,没有任何问题。但是,我正在尝试回滚到较早的 changeset 版本,但出现以下错误。不确定我的maven 配置不正确还是我的命令不正确。

请指导。

命令:

mvn liquibase:rollback -Dliquibase.rollbackTag=01-insertData-addresses-users

错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.516 s
[INFO] Finished at: 2019-05-07T16:30:05-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'liquibase' in the current project and in the plugin groups [org.mule.tools, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\R649526\.m2\repository), orgc-public (http://repo-proxy.org
org.net/maven/content/groups/orgc-public/), myrepo (http://repo.orgc.net/maven/content/repositories/MYREPO)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

src/main/resources/db/changelog/db.changelog-master.yaml

databaseChangeLog:
  - changeSet:
      id: 01-createTable-addresses-users
      author: Nital Chandel
      changes:
        - sqlFile:
            dbms: h2
            encoding: utf8
            endDelimiter: ;
            path: scripts/01/01-ddl.sql
            relativeToChangelogFile: true
            splitStatements: true
            stripComments: true

  - changeSet:
      id: 01-insertData-addresses-users
      author: Nital Chandel
      changes:
        - sqlFile:
            dbms: h2
            encoding: utf8
            path: scripts/01/01-dml.sql
            relativeToChangelogFile: true
            splitStatements: true
            stripComments: true

  - changeSet:
      id: 02-createTable-project
      author: Nital Chandel
      changes:
        - sqlFile:
            dbms: h2
            encoding: utf8
            endDelimiter: ;
            path: scripts/02/02-ddl.sql
            relativeToChangelogFile: true
            splitStatements: true
            stripComments: true

  - changeSet:
      id: 02-insertData-project
      author: Nital Chandel
      changes:
        - sqlFile:
            dbms: h2
            encoding: utf8
            path: scripts/02/02-dml.sql
            relativeToChangelogFile: true
            splitStatements: true
            stripComments: true

src/main/resources/db/changelog/scripts/01/01-ddl.sql

CREATE TABLE ADDRESSES
(
  ID     NUMBER        NOT NULL,
  STREET VARCHAR2(100) NOT NULL,
  CITY   VARCHAR2(100),
  PIN    NUMBER(6),
  CONSTRAINT ADDRESSES_PK PRIMARY KEY (ID)
);

CREATE TABLE USERS
(
  ID      NUMBER       NOT NULL,
  NAME    VARCHAR2(50) NOT NULL,
  EMAIL   VARCHAR2(100),
  PHONE   NUMBER,
  ADDRESS NUMBER       NOT NULL,
  CONSTRAINT USERS_PK PRIMARY KEY (ID),
  CONSTRAINT USERS_FK FOREIGN KEY (ADDRESS) REFERENCES ADDRESSES (ID)
);          

src/main/resources/db/changelog/scripts/01/01-dml.sql

insert into ADDRESSES(ID, STREET, CITY, PIN) values (1, 'street1', 'city1', 111111);
insert into ADDRESSES(ID, STREET, CITY) values (2, 'street2', 'city2');

insert into USERS(ID, NAME, EMAIL, ADDRESS) values (1, 'Soumitra', 'soumitra@email.com', 1);
insert into USERS(ID, NAME, EMAIL, PHONE, ADDRESS) values (2, 'Suman', 'suman@email.com', 1254789541, 2);

src/main/resources/db/changelog/scripts/02/02-ddl.sql

CREATE TABLE PROJECT
(
  ID      NUMBER              NOT NULL PRIMARY KEY,
  NAME    VARCHAR2(256)       NOT NULL,
  CODE    VARCHAR2(10),
  ENABLED CHAR(1) DEFAULT 'Y' NOT NULL
);

src/main/resources/db/changelog/scripts/02/02-dml.sql

insert into PROJECT(ID, NAME, CODE) values (1, 'Project 1', 'A');
insert into PROJECT(ID, NAME, CODE) values (2, 'Project 2', 'B');

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>projectstar</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>projectstar</name>
    <description>Project management tool</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

注意:我已经浏览过这个类似的 SO 链接 (Liquibase Rollback Spring boot),但它对我没有帮助,原因有两个。首先,它没有显示 maven 和 spring-boot 配置如何执行回滚,其次,我的示例中的变更集是使用 .yaml 文件编写的,该文件指向 .sql 文件,这与上面链接中提到的文件完全不同.请不要将此标记为重复。

【问题讨论】:

    标签: java spring maven spring-boot liquibase


    【解决方案1】:

    不确定是我的maven配置不正确还是我的命令不正确。

    错误消息No plugin found for prefix 'liquibase' in the current project 表示Maven 找不到具有该名称的插件。所以,在这种情况下,你的 maven 配置是不完整的。

    您需要在pom.xml 文件中定义liquibase-maven-plugin。此外,您可能需要调整其配置以指向 Spring Boot 使用的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 2014-04-24
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      相关资源
      最近更新 更多