liquibase 忽略已经执行的变更集

liquibase ignores already executed changeSets

我正在尝试使用现有数据库(在 MySQL 上)中的 liquibase (3.5.5)。

  1. 我已经使用 generateChangeLog 命令生成了一个 db.changelog.xml 文件。

    C:/liquibase-3.5.5/liquibase.bat --driver=com.mysql.jdbc.Driver ^ --classpath=C:/Libraries/mysql-connector-java-5.1.37-bin.jar ^ --changeLogFile=db.changelog.xml ^ --url="jdbc:mysql://vbalder/izalerting" ^ --用户名=* ^ --密码=* ^ generateChangeLog

结果:Liquibase 'generateChangeLog' Successful

生成的 db.changelog.xml 文件包含作者 BGADEYNE (generated) 和 id 前缀为 1533645947580- 的变更集。例如1533645947580-1

  1. 已将 logicalFilePath="db.changelog.xml" 添加到 databaseChangeLog 标记
  2. 我使用 changelogSync 命令创建并填充了 DATABASECHANGELOG 和 DATABASECHANGELOGLOCK table。它们确实包含每个 changeSet 的行。

    C:/liquibase-3.5.5/liquibase --driver=com.mysql.jdbc.Driver ^ --classpath=C:/Libraries/mysql-connector-java-5.1.37-bin.jar ^ --changeLogFile=db.changelog.xml ^ --url="jdbc:mysql://vbalder/izalerting" ^ --用户名=izalerting ^ --密码=阿尔法^ changelogSync

结果:Liquibase 'changelogSync' Successful

  1. 创建了一个 CDI 组件以在应用程序启动时执行 db.changelog.xml。

添加了 Maven 依赖项:

<dependency>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-cdi</artifactId>
    <version>3.5.5</version>
</dependency>

添加了 CLI 组件:

@Dependent
public class LiquibaseProducer {
    @Resource(name="java:/izalerting")
    private DataSource dbConnection;

    @Produces @LiquibaseType
    public CDILiquibaseConfig createConfig() {
        CDILiquibaseConfig config = new CDILiquibaseConfig();
        config.setChangeLog("be/uzgent/iz/alerting/liquibase/db.changelog.xml");
        config.setContexts("non-legacy");
        return config;
    }

    @Produces @LiquibaseType
    public DataSource createDataSource() throws SQLException {
        return dbConnection;
    }

    @Produces @LiquibaseType
    public ResourceAccessor create() {
        return new ClassLoaderResourceAccessor(getClass().getClassLoader());
    }
}
  1. 将应用程序部署到 WildFly 时我可以看到这个

    2018-08-07 15:07:09,234 错误 [stderr](MSC 服务线程 1-4)信息 8/7/18 3:07 下午:liquibase.integration.cdi.CDILiquibase:启动 Liquibase 3.5.4 2018-08-07 15:07:09,285 错误 [stderr](MSC 服务线程 1-4)信息 8/7/18 3:07 PM:liquibase:成功获取更改日志锁 2018-08-07 15:07:09,781 错误 [stderr](MSC 服务线程 1-4)信息 8/7/18 3:07 PM:liquibase:从 PUBLIC.DATABASECHANGELOG 读取 2018-08-07 15:07:09,814 错误 [stderr](MSC 服务线程 1-4)严重 8/7/18 3:07 PM:liquibase:db.changelog.xml:db.changelog.xml ::1533645947580-1::BGADEYNE(生成):更改集 db.changelog.xml::1533645947580-1::BGADEYNE(生成)失败。错误:Table "ALERTRESULT" 已经存在; SQL声明: 2018-08-07 15:07:09,815 错误 [stderr](MSC 服务线程 1-4)创建 TABLE PUBLIC.alertresult(triggerid VARCHAR(255) NOT NULL,application VARCHAR(40) NOT NULL,resultid INT NOT NULL,subject VARCHAR(255),content CLOB,contenturl CLOB,executetime TIMESTAMP,html BOOLEAN DEFAULT TRUE NOT NULL,alertlevel VARCHAR(20) DEFAULT 'INFO' NOT NULL,closable BOOLEAN DEFAULT TRUE NOT NULL,screenwidth INT,screenheight INT)[42101-173] [失败SQL:创建TABLE PUBLIC.alertresult(triggerid VARCHAR(255)NOT NULL,应用程序VARCHAR (40) NOT NULL, resultid INT NOT NULL, subject VARCHAR(255), 内容 CLOB, contenturl CLOB, executetime TIMESTAMP, html BOOLEAN DEFAULT TRUE NOT NULL, alertlevel VARCHAR(20) DEFAULT 'INFO' NOT NULL, closable BOOLEAN DEFAULT TRUE NOT NULL, screenwidth INT, screenheight INT)] 2018-08-07 15:07:09,816 错误 [stderr](MSC 服务线程 1-4)信息 8/7/18 3:07 PM:liquibase:db.changelog.xml::1533645947580-1: :BGADEYNE(生成):成功释放更改日志锁

DATABASECHANGELOG table 包含每个 changeSet 的一行。

+------------------+-----------------------+-------------------+-----------+
|       # ID       |         AUTHOR        |      FILENAME     |  EXECTYPE |
+------------------+-----------------------+-------------------+-----------+
| 1533645947580-1  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-2  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-3  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-4  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-5  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-6  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-7  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-8  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-9  |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-10 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-11 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-12 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-13 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-14 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-15 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-16 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-17 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-18 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-19 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
| 1533645947580-20 |  BGADEYNE (generated) |  db.changelog.xml |  EXECUTED |
+------------------+-----------------------+-------------------+-----------+

有人知道我做错了什么吗?

而不是

@Resource(name="java:/izalerting")

我需要使用

@Resource(lookup="java:/izalerting")

关于野蝇 9