Liquibase prerequisites do not work

I am trying to use Liquibase to track changes in a postgresql database using dropwizard-migrations. I would like to be able to start the migration in an existing production database instead of restoring from scratch. I'm testing the scene right now. I created a prerequisite change set.

<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 change set if the sequence already exists. It seems simple, but it does not work.

 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 

I tried to use MARK_RAN instead of CONTINUE. No luck with that.

+4
source share
4 answers

I solved this by running the "fast forward" dropwizard-migrations command as follows:

 java -jar hello-world.jar db fast-forward helloworld.yml 

This will mean the following set of changes, applied without applying it. You may need to do this once for each set of changes you want to fast forward. There is also the "all" flag if you want to forward everything quickly.

More information can be found here: http://dropwizard.codahale.com/manual/migrations/

0
source

An easier way to apply your change sets to an existing database without execution is to use the changelogSync command.

The following commands demonstrate how to extract the change log and then synchronize it with the current database:

 liquibase --changeLogFile=mydb.xml generateChangeLog liquibase --changeLogFile=mydb.xml changelogSync 

What the sync command does is create all the entries in the change table so that the Liquibase file can now be used as usual to update the database:

 liquibase --changeLogFile=mydb.xml update 
+4
source

I did the same thing you want to do with the view, and for me this works:

Maybe you will be asked:

 <changeSet author="e-ballo" id="DropViewsAndcreateSynonyms" context="dev,int,uat,prod"> <preConditions onFail="CONTINUE" > <viewExists viewName="PMV_PACKAGE_ITEMS" schemaName="ZON"/> <viewExists viewName="PMV_SUBSPLAN_INSTALLTYPES" schemaName="ZON"/> </preConditions> <dropView schemaName="ZON" viewName="PMV_PACKAGE_ITEMS" /> <dropView schemaName="ZON" viewName="PMV_SUBSPLAN_INSTALLTYPES" /> <sqlFile path="environment-synonyms.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true"/> </changeSet> 

I hope this helps

0
source

I solved this problem using the sqlCheck statement:

 <changeSet id="sys-0" context="structural"> <preConditions onFail="MARK_RAN"><sqlCheck expectedResult="0">SELECT count(c.relname) FROM pg_class c WHERE c.relkind = 'S' and c.relname = 'hibernate_sequence'</sqlCheck></preConditions> <!-- <preConditions><not><sequenceExists schemaName="public" sequenceName="hibernate_sequence"/></not></preConditions> --> <createSequence schemaName="public" sequenceName="hibernate_sequence"/> </changeSet> 

(tested on Liquibase 2.0.1)

0
source

Source: https://habr.com/ru/post/1502131/


All Articles