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

可以创建表,并且也可以毫无问题地填充数据。但是,我试图回滚到早期的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', '[email protected]', 1);
insert into USERS(ID, NAME, EMAIL, PHONE, ADDRESS) values (2, 'Suman', '[email protected]', 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文件与上面链接中提到的文件完全不同。 。请不要将此标记为重复。

最佳答案

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


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

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

10-02 21:37