本文介绍了了解Liquibase中logicalFilePath的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个变更集具有一个不正确的逻辑文件路径(两个变更集意外地具有相同的逻辑文件路径),并且在现有变更集中编辑逻辑文件路径时,liquibase更新失败,并出现重复列错误,这意味着liquibase认为该变更集不执行并重新运行.

One of my changesets had a logicalFilePath which was incorrect(two changesets accidentally had the same logicalFilePath) and upon editing the logicalFilePath in an existing changeset, liquibase update failed with an error of duplicate column, which would mean that liquibase thought the changeset to be not executed and re-ran it.

liquibase是否基于"EXECUTED"标志或"id","author"和"logicalFilePath"的组合来识别变更集是否已执行?

Does liquibase identify if a changeset has already been executed based on the 'EXECUTED' flag or the combination of 'id','author' and 'logicalFilePath'?

此外,在现有变更集具有不正确的logicalFilePath的情况下,我该如何纠正错误

Also, how do i rectify the mistake in this case where an existing changeset has an incorrect logicalFilePath

推荐答案

工作原理:

从Liquibase文档中:

From Liquibase docs:

Liquibase根据以下内容计算changeSet的MD5校验和:

Liquibase calculates the MD5 checksum of the changeSet based on the:

  • changeSet的内容;
  • changeSet的ID;
  • changeSet的作者;
  • changeLog文件或logicalFilePath的路径和名称;
  • content of the changeSet;
  • id of the changeSet;
  • author of the changeSet;
  • path and name of your changeLog file or logicalFilePath;

如果您未更改任何内容,并尝试重新运行,则Liquibase将查看databasechangelog.iddatabasechangelog.authordatabasechangelog.FILENAMEdatabasechangelog.MD5SUM,如果一切都一样,那么changeSet将被跳过.

If you don't change anything in your changeSet and just try to rerun it, Liquibase will look at databasechangelog.id, databasechangelog.author, databasechangelog.FILENAME and databasechangelog.MD5SUM, and if everything is the same as it was, then the changeSet will be skipped.

如果更改changeSet的内容,则liquibase将抛出一个错误,即校验和已更改(而databasechangelog.iddatabasechangelog.authordatabasechangelog.FILENAME保持一样).

If you change the content of the changeSet, liquibase will throw an error that checksum was changed (while databasechangelog.id, databasechangelog.author and databasechangelog.FILENAME stays the same).

如果更改了ID,作者或路径(逻辑文件路径),那么Liquibase会认为这是一个新的changeSet并将尝试执行它.

If you change the id, author or path (logicalFilePath), then Liquibase will think that it's a new changeSet and will try to execute it.

您为什么遇到问题:

Liquibase将您的changeSet视为新的,并且出现错误:

Liquibase treats you changeSet as new, and as you have an error:

我想您的changeSet中没有任何preConditions或它们不够用,

I suppose you don't have any preConditions in your changeSet or they aren't sufficient enough,

您如何解决它:

因此,由于liquibase认为您正在执行新的changeSet,因此没有什么可以阻止您编写这些内容:

So since liquibase thinks that you're executing a new changeSet, nothing stops you from writing those:

<preConditions onFail="MARK_RAN">
    <not>
        <columnExists tableName="your_table" columnName="your_column"/>
    </not>
</preConditions>

,并且由于your_table.your_column已存在于数据库中,因此此changeSet将被标记为databasechangelog.EXECTYPE=MARK_RAN并被跳过.

and because your_table.your_column already exists in the database, then this changeSet will be marked as databasechangelog.EXECTYPE=MARK_RAN and skipped.

问题解决了!

这篇关于了解Liquibase中logicalFilePath的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 14:56