Liquibase前提条件不起作用 [英] Liquibase preconditions not working
问题描述
我正尝试使用liquibase通过dropwizard-migrations跟踪对Postgresql数据库的更改.我希望能够在现有生产数据库上运行迁移,而不是从头开始重建.目前,我正在分阶段进行测试.我已经创建了一个带有前提条件的变更集.
I'm trying to use liquibase to track changes to a postgresql database using dropwizard-migrations. I'd like to be able to run the migration on the existing production database instead of rebuilding from scratch. Right now I'm testing in staging. I've created a changeset with a precondition.
<changeSet id="3" author="me">
<preConditions onFail="CONTINUE">
<not>
<sequenceExists sequenceName="emails_id_seq"/>
</not>
</preConditions>
<createSequence sequenceName="emails_id_seq" startValue="1" incrementBy="1" />
</changeSet>
我的目标是如果序列已经存在,则跳过应用变更集.看起来很简单,但是没有用.
My goal is to skip applying the changeset if the sequence is already there. Seems straightforward, but it's not working.
ERROR [2013-09-13 22:19:22,564] liquibase: Change Set migrations.xml::3::me failed. Error: Error executing SQL CREATE SEQUENCE emails_id_seq START WITH 1 INCREMENT BY 1: ERROR: relation "emails_id_seq" already exists
! liquibase.exception.DatabaseException: Error executing SQL CREATE SEQUENCE emails_id_seq START WITH 1 INCREMENT BY 1: ERROR: relation "emails_id_seq" already exists
我也尝试过使用MARK_RAN而不是CONTINUE.运气不好.
I've tried using the MARK_RAN instead of CONTINUE too. No luck with that.
推荐答案
我通过运行dropwizard-migrations"fast-forward"命令来解决此问题,如下所示:
I solved this by running the dropwizard-migrations "fast-forward" command as follows:
java -jar hello-world.jar db fast-forward helloworld.yml
这会将下一个变更集标记为已应用,而没有实际应用.您可能需要对每个要快速前进的变更集执行一次此操作.如果您想快速转发所有内容,则还有一个--all标志.
This will mark the next changeset as applied without actually applying it. You may have to do this one time per changeset you want to fast-forward. There is also an --all flag if you want to fast forward everything.
可在此处找到更多详细信息: http://dropwizard.codahale.com/manual/migrations/
More details can be found here: http://dropwizard.codahale.com/manual/migrations/
这篇关于Liquibase前提条件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!