# Bug/inconvenience in preConditions

**URL:** <https://forum.liquibase.org/t/bug-inconvenience-in-preconditions/196>\
**Category:** General Discussion\
**Created:** [August 13, 2009, 5:14pm UTC](https://forum.liquibase.org/t/bug-inconvenience-in-preconditions/196 "2009-08-13T17:14:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![justx2](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@justx2](https://forum.liquibase.org/u/justx2)\
**Post date:** [August 13, 2009, 5:14pm UTC](https://forum.liquibase.org/t/bug-inconvenience-in-preconditions/196/1 "2009-08-13T17:14:00Z")

</div>

When a preConditions is attached to a changeSet in will not be evaluated until the migrator gets to that particular changeset,  
but if the same preConditions is attached to a changelog it will be evaluated before any migration.  
That is a problem because the changelog can be executed from an include, but still it is evaluated before any prior includes are executed.

All\_Refactorings.xml

\<?xml version="1.0" encoding="UTF-8"?\> http://www.liquibase.org/xml/ns/dbchangelog/1.9" &nbsp; xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance%22) &nbsp; xsi:schemaLocation="[http://www.liquibase.org/xml/ns/dbchangelog/1.9](http://www.liquibase.org/xml/ns/dbchangelog/1.9) &nbsp; [http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"\>](http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd%22>)

&nbsp; &nbsp;   
&nbsp; &nbsp;   
&nbsp; &nbsp;

Refactoring\_1.xml

\<?xml version="1.0" encoding="UTF-8"?\> http://www.liquibase.org/xml/ns/dbchangelog/1.9" &nbsp; xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance%22) &nbsp; xsi:schemaLocation="[http://www.liquibase.org/xml/ns/dbchangelog/1.9](http://www.liquibase.org/xml/ns/dbchangelog/1.9) &nbsp; [http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"\>](http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd%22>) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

Example 1: preConditions attached to a changeSet  
Refactoring\_2.xml

\<?xml version="1.0" encoding="UTF-8"?\> http://www.liquibase.org/xml/ns/dbchangelog/1.9" &nbsp; xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance%22) &nbsp; xsi:schemaLocation="[http://www.liquibase.org/xml/ns/dbchangelog/1.9](http://www.liquibase.org/xml/ns/dbchangelog/1.9) &nbsp; [http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"\>](http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd%22>)

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

Executing All\_Refactorings will be succesfull both if Refactoring\_1 is already executed before and if Refactoring\_1 is not executed before and should therefore be executed in this migration.

Example 2: preConditions attached to a changelog  
Refactoring\_2.xml

\<?xml version="1.0" encoding="UTF-8"?\> http://www.liquibase.org/xml/ns/dbchangelog/1.9" &nbsp; xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance%22) &nbsp; xsi:schemaLocation="[http://www.liquibase.org/xml/ns/dbchangelog/1.9](http://www.liquibase.org/xml/ns/dbchangelog/1.9) &nbsp; [http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"\>](http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd%22>)

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

Executing All\_Refactorings will be succesfull if Refactoring\_1 is already executed before, but will fail if Refactoring\_1 is not executed before and should therefore be executed in this migration.

This makes preConditions attached to changelogs pritty unusable at the moment.

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [August 13, 2009, 5:14pm UTC](https://forum.liquibase.org/t/bug-inconvenience-in-preconditions/196/2 "2009-08-13T17:14:00Z")

</div>

That behavior is by design.&nbsp; The goal of changeLog wide preconditions is to make checks that should be ran before anything is attempted.&nbsp; A good example is a “running under mysql” precondition.&nbsp; You may specify that in an included changelog to document/test that the assumption you made when creating the changelog is correct.&nbsp; The tests that make the most sense in changeLog preconditions are more static tests like runningAs or dbms.&nbsp;

The changeSet preconditions, on the other hand, are designed to be ran as part of the execution stream.

What you probably want to do is convert your changeLog wide precondition in refactoring\_2 to be a changeSet precondition:

\<?xml version="1.0" encoding="UTF-8"?\> http://www.liquibase.org/xml/ns/dbchangelog/1.9" &nbsp; xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance%22) &nbsp; xsi:schemaLocation="[http://www.liquibase.org/xml/ns/dbchangelog/1.9](http://www.liquibase.org/xml/ns/dbchangelog/1.9) &nbsp; [http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"\>](http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd%22>)

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp;   
&nbsp; &nbsp;

Nathan

---

<div class="post-metadata">

**Author:** ![justx2](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@justx2](https://forum.liquibase.org/u/justx2)\
**Post date:** [August 13, 2009, 5:14pm UTC](https://forum.liquibase.org/t/bug-inconvenience-in-preconditions/196/3 "2009-08-13T17:14:00Z")

</div>

Ok, that makes sense. Your solution will work fine for me.  
Perhaps the documentation should be a little more specific about this.
