Search code examples
jakarta-eeflywayjboss-arquillian

arquillian and flyway: Migrations are not executed


I have arquillian tests run on an embedded wildfly. Even though all the migration scripts, the Integrator class (where FlyWay is setup) and all the flyway packages (from POM files) are included with shrinkwrap in the .war file (which is deployed on the embedded wildfly), no migration is done.

Is there any reason for this? Does this principially not work or do I have missed something?

What I like to achieve is that the automated tests run by arquillian will setup an in memory database having the same scheme as the productive database using the same migration scripts.

edit: as ytg asked below, I add the Integrator class; however, this code is not entered in the arquillian test; if I set a breakpoint on top of the integrate method, it will never be hit. Why?

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;

public class FlywayIntegrator implements Integrator
{
    @Override
    public void integrate(final Configuration configuration,
                          final SessionFactoryImplementor sessionFactoryImplementor,
                          final SessionFactoryServiceRegistry sessionFactoryServiceRegistry)
    {

        System.out.println("Starting Flyway database migrations");

        Flyway flywayEvending = new Flyway();

        // enable this to migrate from the state currently on useqrnow.com
        flywayEvending.setBaselineVersionAsString("0");
        flywayEvending.setBaselineOnMigrate(true);
        flywayEvending.setDataSource(...)

        flywayEvending.setLocations(...);
        for (MigrationInfo i : flywayEvending.info().all())
        {
            System.out.println("migrate task: " + i.getVersion() + " : " + i.getDescription() + " from file: " + i.getScript());
        }
        flywayEvending.migrate();
    }

    @Override
    public void integrate(final MetadataImplementor metadataImplementor, final SessionFactoryImplementor sessionFactoryImplementor, final SessionFactoryServiceRegistry sessionFactoryServiceRegistry)
    {
        // do nothing
    }

    @Override
    public void disintegrate(final SessionFactoryImplementor sessionFactoryImplementor, final SessionFactoryServiceRegistry sessionFactoryServiceRegistry)
    {
        // do nothing
    }
}

Solution

  • After a long time, I retried to solve this problem. And it was just easy: I missed to add the file META-INF/services/org.hibernate.integrator.spi.Integrator in which we have to store the integrator class. I needed to add this file to the .war, which ShrinkWrap creates.