Java Code Examples for org.flywaydb.core.Flyway#clean()
The following examples show how to use
org.flywaydb.core.Flyway#clean() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlyWayConfig.java From mojito with Apache License 2.0 | 6 votes |
@Bean public FlywayMigrationStrategy cleanMigrateStrategy() { FlywayMigrationStrategy strategy = new FlywayMigrationStrategy() { @Override public void migrate(Flyway flyway) { if (clean) { logger.info("Clean DB with Flyway"); flyway.clean(); } else { logger.info("Don't clean DB with Flyway"); } flyway.migrate(); } }; return strategy; }
Example 2
Source File: AbstractFlywayMigration.java From micronaut-flyway with Apache License 2.0 | 5 votes |
private void runFlyway(FlywayConfigurationProperties config, Flyway flyway) { if (config.isCleanSchema()) { if (LOG.isInfoEnabled()) { LOG.info("Cleaning schema for database with qualifier [{}]", config.getNameQualifier()); } flyway.clean(); eventPublisher.publishEvent(new SchemaCleanedEvent(config)); } if (LOG.isInfoEnabled()) { LOG.info("Running migrations for database with qualifier [{}]", config.getNameQualifier()); } flyway.migrate(); eventPublisher.publishEvent(new MigrationFinishedEvent(config)); }
Example 3
Source File: AbstractFlywayDbTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Bootstrapping public static void prepareDataBase(final DataSource ds) { // creates db schema and puts some data final Flyway flyway = new Flyway(); flyway.setDataSource(ds); flyway.clean(); flyway.migrate(); }
Example 4
Source File: AbstractFlywayDbJunit5Test.java From jpa-unit with Apache License 2.0 | 5 votes |
@Bootstrapping public static void prepareDataBase(final DataSource ds) { // creates db schema and puts some data final Flyway flyway = new Flyway(); flyway.setDataSource(ds); flyway.clean(); flyway.migrate(); }
Example 5
Source File: UserSaltMigrationTest.java From credhub with Apache License 2.0 | 5 votes |
@SuppressFBWarnings( value = { "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", "ODR_OPEN_DATABASE_RESOURCE", }, justification = "Ignore that jdbcTemplate methods might return null or that the DB connection may be left open." ) @Before public void beforeEach() throws Exception { canaries = encryptionKeyCanaryRepository.findAll(); databaseName = jdbcTemplate.getDataSource() .getConnection() .getMetaData() .getDatabaseProductName() .toLowerCase(); Flyway flywayV40 = Flyway .configure() .target(MigrationVersion.fromVersion("40")) .dataSource(flyway.getConfiguration().getDataSource()) .locations(flyway.getConfiguration().getLocations()) .load(); flywayV40.clean(); flywayV40.migrate(); }
Example 6
Source File: EarlyCredentialMigrationTest.java From credhub with Apache License 2.0 | 5 votes |
@Before public void beforeEach() { canaries = encryptionKeyCanaryRepository.findAll(); Flyway flywayV4 = Flyway .configure() .target(MigrationVersion.fromVersion("4")) .dataSource(flyway.getConfiguration().getDataSource()) .locations(flyway.getConfiguration().getLocations()) .load(); flywayV4.clean(); flywayV4.migrate(); }
Example 7
Source File: PersistenceLayer.java From demo with MIT License | 4 votes |
@Override public void cleanDatabase() { Flyway flyway = configureFlyway(); flyway.clean(); }
Example 8
Source File: MigrationsRule.java From keywhiz with Apache License 2.0 | 4 votes |
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile()); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); ObjectMapper objectMapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper()); KeywhizConfig config = new YamlConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw") .build(yamlFile); DataSource dataSource = config.getDataSourceFactory() .build(new MetricRegistry(), "db-migrations"); Flyway flyway = Flyway.configure().dataSource(dataSource).locations(config.getMigrationsDir()).table(config.getFlywaySchemaTable()).load(); flyway.clean(); flyway.migrate(); DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource); DbSeedCommand.doImport(dslContext); base.evaluate(); } }; }
Example 9
Source File: DbCleanCommand.java From dropwizard-flyway with Apache License 2.0 | 4 votes |
@Override protected void run(final Namespace namespace, final Flyway flyway) throws Exception { flyway.clean(); }
Example 10
Source File: DatabaseMigrator.java From lemon with Apache License 2.0 | 4 votes |
@PostConstruct public void init() { if (!enabled) { logger.info("skip dbmigrate"); return; } long startTime = System.currentTimeMillis(); if (clean) { logger.info("clean database"); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.clean(); } Map<String, ModuleSpecification> map = applicationContext .getBeansOfType(ModuleSpecification.class); for (ModuleSpecification moduleSpecification : map.values()) { if (!moduleSpecification.isEnabled()) { logger.info("skip migrate : {}, {}", moduleSpecification.getSchemaTable(), moduleSpecification.getSchemaLocation()); continue; } String schemaTable = moduleSpecification.getSchemaTable(); if (schemaTable.length() > 30) { logger.warn("table name cannot larger then 30 : {} {}", schemaTable.length(), schemaTable); continue; } this.doMigrate(schemaTable, moduleSpecification.getSchemaLocation()); if (moduleSpecification.isInitData()) { this.doMigrate(moduleSpecification.getDataTable(), moduleSpecification.getDataLocation()); } } long endTime = System.currentTimeMillis(); logger.info("dbmigrate cost : {} ms", (endTime - startTime)); }
Example 11
Source File: FlywayTestExecutionListener.java From flyway-test-extensions with Apache License 2.0 | 4 votes |
/** * Test the annotation an reset the database. * * @param testContext * default test context filled from spring * @param annotation * founded */ private void dbResetWithAnnotation(final TestContext testContext, final FlywayTest annotation) { if (annotation != null) { Flyway flyWay = null; final ApplicationContext appContext = testContext .getApplicationContext(); if (appContext != null) { flyWay = getBean(appContext, Flyway.class, annotation.flywayName()); if (flyWay != null) { String executionInfo = ""; // we have a fly way configuration no lets try if (logger.isInfoEnabled()) { executionInfo = ExecutionListenerHelper .getExecutionInformation(testContext); logger.info("---> Start reset database for '" + executionInfo + "'."); } if (annotation.invokeCleanDB()) { if (logger.isDebugEnabled()) { logger.debug("******** Clean database for '" + executionInfo + "'."); } flyWay.clean(); } if (annotation.invokeBaselineDB()) { if (logger.isDebugEnabled()) { logger.debug("******** Baseline database for '" + executionInfo + "'."); } flyWay.baseline(); } if (annotation.invokeMigrateDB()) { String[] locations = annotation.locationsForMigrate(); if ((locations == null || locations.length == 0)) { if (logger.isDebugEnabled()) { logger.debug("******** Default migrate database for '" + executionInfo + "'."); } flyWay.migrate(); } else { locationsMigrationHandling(annotation, flyWay, executionInfo); } } if (logger.isInfoEnabled()) { logger.info("<--- Finished reset database for '" + executionInfo + "'."); } return; } // in this case we have not the possibility to reset the // database throw new IllegalArgumentException("Annotation " + annotation.getClass() + " was set, but no Flyway configuration was given."); } // in this case we have not the possibility to reset the database throw new IllegalArgumentException("Annotation " + annotation.getClass() + " was set, but no configuration was given."); } else { if (logger.isDebugEnabled()) { logger.debug("dbResetWithAnnotation is called without a flyway test annotation."); } } }