Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit baseline triggered by baselineOnMigrate does not respect baselineVersion #940

Closed
JohnSAdair opened this issue Jan 23, 2015 · 8 comments

Comments

@JohnSAdair
Copy link

When baseline is triggered implicitly by migration with baselineOnMigrate set to true, it does not respect the baseline version specified by baselineVersion, and instead tries to run all migrations.

Will attach SSCCE.

I would have thought this bug is the same problem as issue #842, but I am still seeing it in flyway 3.1.

@JohnSAdair
Copy link
Author

I have a small maven project that illustrates the problem, but can't figure out how to attach it to the issue. Here's the junit test class. It also requires a V1 migration with invalid SQL and a V2 migration with valid SQL.

import java.sql.SQLException;

import org.flywaydb.core.Flyway;
import org.h2.jdbcx.JdbcConnectionPool;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Illustrates problem with baselineOnMigrate and baselineVersion.
 */
public class FlywayTest {

  private static JdbcConnectionPool dataSource;

  @BeforeClass
  public static void setup() throws SQLException {
    dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test", "sa", "sa");
  }

  @AfterClass
  public static void cleanup() throws SQLException {
    dataSource.dispose();
  }

  @Test
  public void testFlywayExplicitBaseline() throws SQLException {
    exerciseFlyway(true);
  }

  // This test fails because the implicit baseline triggered by the
  // migration does not respect the baseline version, and tries to
  // execute the invalid SQL in version 1.
  @Test
  public void testFlywayImplicitBaseline() throws SQLException {
    exerciseFlyway(false);
  }

  private void exerciseFlyway(boolean explicitBaseline) {
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setTable("schema_version");
    flyway.setBaselineOnMigrate(true);
    flyway.setLocations("migrations");
    flyway.setBaselineVersion("2");
    flyway.clean();
    if (explicitBaseline) {
      flyway.baseline();
    }
    flyway.migrate();
  }
}

@JohnSAdair
Copy link
Author

Workaround is to call baseline explicitly before migration, and catch and ignore the exceptions that come from trying to baseline more than once.

@axelfontaine
Copy link
Contributor

This was somehow fixed by another fix to baseline. I've added another test case just to be on the safe side.

Cheers
Axel

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Mar 4, 2015
@mdwn
Copy link

mdwn commented May 20, 2016

I've just run into this issue on Spring-Boot 1.3.2, which uses Flyway 3.2.1.

@oey
Copy link

oey commented Aug 30, 2017

I get this issue with the Command line tool. I've tested with Flyway 4.0.1, 4.1.1 and 4.2.0.

Using the Baseline command it baselines from specified version, but BaselineOnMigrate tries to run all migrations.

@Webenius
Copy link

Webenius commented Feb 8, 2018

I'm using Postgresql & Flyway 5.0.0 in a spring (not boot) application and I want that flyway does not execute the migrations < 1.5 (even if it is run for the first time on an existing db with no flyway_schema_history). But it executes always all the migrations and ignores the value of baselineVersionAsString:

<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
        <property name="baselineOnMigrate" value="true" />
        <property name="baselineVersionAsString" value="1.5" />
        <property name="dataSource" ref="dataSource" />
    </bean>

baselineVersion is ignored too:

<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
        <property name="baselineOnMigrate" value="true" />
        <property name="baselineVersion">
            <bean class="org.flywaydb.core.api.MigrationVersion">
                <constructor-arg value="5"></constructor-arg>
            </bean>
        </property>
        <property name="locations" value="classpath:db.migration" />
        <property name="dataSource" ref="dataSource" />
    </bean>

am I missing something or doing it wrong to get what I want? Any help will be appreciated.

Thanks

@ograndebe
Copy link

I Had the same problem here. Even executing baselineOnMigrate or directly baseline command. Flyway tries to execute migrate all migrations.

@kippm
Copy link

kippm commented Oct 8, 2019

Still having this problem in version 6.0.4, that all migrations are executed, even though baselineOnMigrate is set to true. Using the command line on Windows, btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants