Summary: I updated my classes, test classes and my database to login with email. I wrote a liquibase's changelog to make database's changes.
Running the project, all worked fine but if I execute integration tests liquibase's changelogs are working bad.

What I think that it is happening: 

1. I try to execute tests.
2. H2 database is initialized with every changelog (initial and customs)
3. Tests begin to be executed.
4. Before every tests, H2 database is not deleted but changelogs are invocated (or only my custom changelog).
5. My custom changelogs fails because it cannot find login column that was deleted on point 2 and It was not "restaurated" by initial
changelog.

Complete version: I had generated a JHipster application with 4.8.0. My .yo-rc.json:

```
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.company.name",
      "nativeLanguage": "es"
    },
    "jhipsterVersion": "4.8.0",
    "baseName": "name",
    "packageName": "com.company.name",
    "packageFolder": "com/company/name",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "no",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "gradle",
    "enableSocialSignIn": false,
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "secret",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "es",
    "languages": [
      "es"
    ]
  }
}

```

I wanted to drop login column from JHI\_USER and drop unique constraint from JHI\_USER's email and make it not null, then, I made every code changes that I needed (I removed every reference to login and I changed them to email) and coded three liquibase changelog's files:

a) 20170913130000\_drop\_login\_column\_JhiUser.xml:

```
<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet id="20170913130000" author="svalero">
        <dropColumn columnName="login" tableName="jhi_user" />
    </changeSet>
</databaseChangeLog>

```

B) 20170913180000\_drop\_unique\_constraint\_email\_JhiUser.xml:

```
<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet id="20170913180000" author="svalero">
        <dropUniqueConstraint constraintName="jhi_user_email_key"
            tableName="jhi_user" />
    </changeSet>
</databaseChangeLog>

```

C) 20170913182100\_add\_notnull\_constraint\_email\_JhiUser.xml

```
<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet id="20170913182100" author="svalero">
        <addNotNullConstraint columnDataType="varchar(100)"
            columnName="email"
            tableName="jhi_user"/>
    </changeSet>
</databaseChangeLog>

```

I also added them on master.xml and everything worked perfectly on the application (./gradlew and yarn start).

But, when I tried to execute integration test (./gradlew test) I got this on every test:

```
com.company.name.web.rest.AuditResourceIntTest > getNonExistingAudit FAILED
    java.lang.IllegalStateException
        Caused by: org.springframework.beans.factory.BeanCreationException
            Caused by: liquibase.exception.MigrationFailedException
                Caused by: liquibase.exception.DatabaseException
                    Caused by: org.h2.jdbc.JdbcSQLException

```

From tests results I found this:

```
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [com/company/name/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20170913180000_drop_unique_constraint_email_JhiUser.xml::20170913180000::svalero:
     Reason: liquibase.exception.DatabaseException: Constraint &quot;JHI_USER_EMAIL_KEY&quot; not found; 
     SQL statement: ALTER TABLE PUBLIC.jhi_user DROP CONSTRAINT jhi_user_email_key [90057-196] [Failed SQL: ALTER TABLE PUBLIC.jhi_user DROP CONSTRAINT jhi_user_email_key]

```

Then, I thought that on every test my custom changelog were invocated but the initial changelog were not invocated because my changelog cannot find columns or constraint that initial changelog must create.

My first "walkaround" was easy, add preconditions to changelogs like:

```
<preConditions onFail="MARK_RAN" onError="MARK_RAN">
    <columnExists columnName="login" tableName="jhi_user" schemaName="public" />
</preConditions>

```

But Liquibase does not have a precondition to "unique constraint" and I found this to check if "jhi\_user\_email\_key" constraint exists:

```
<preConditions onFail="MARK_RAN" onError="MARK_RAN">
    <sqlCheck expectedResult="1">select count (*) from pg_constraint where conname='jhi_user_email_key'</sqlCheck>
</preConditions>

```

But in H2 (JHipster use this kind of database to tests) we do not have a pg\_constraint and this does not work.

Finally, what is wrong? Why are tests running only my changelogs and they ignore initial changelog? How can I solve it?