BAEL-4287 - Rolling Back Migrations with Flyway (#9910)
* First commit - Flyway Undo * Simplify migrations Move to own package
This commit is contained in:
parent
3ddc6fd882
commit
1927bb1b46
|
@ -0,0 +1,6 @@
|
|||
create table book (
|
||||
id numeric,
|
||||
title varchar(128),
|
||||
author varchar(256),
|
||||
constraint pk_book primary key (id)
|
||||
);
|
|
@ -0,0 +1 @@
|
|||
drop table book;
|
|
@ -0,0 +1,39 @@
|
|||
package com.baeldung.flywayundo;
|
||||
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.flywaydb.core.api.MigrationInfo;
|
||||
import org.flywaydb.core.api.MigrationState;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = FlywayUndoTestConfig.class)
|
||||
@SpringBootTest
|
||||
public class FlywayUndoMigrationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void givenMigrationsExist_whenApplyMigrations_migrationsAreSuccessful() {
|
||||
Flyway flyway = Flyway.configure()
|
||||
.dataSource(dataSource)
|
||||
.schemas("undo")
|
||||
.locations("db/undo")
|
||||
.load();
|
||||
|
||||
flyway.migrate();
|
||||
|
||||
for (MigrationInfo info : flyway.info().all()) {
|
||||
assertThat(info.getState()).isEqualTo(MigrationState.SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.flywayundo;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class FlywayUndoTestConfig {
|
||||
|
||||
@Bean
|
||||
public DataSource createDatasource() {
|
||||
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
||||
return dbBuilder.setType(EmbeddedDatabaseType.H2)
|
||||
.setName("DATABASE")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue