package com.cloud.flyway;

import com.cloud.legacymodel.exceptions.CloudRuntimeException;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.FlywayException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class FlywayDB {

    private static final Logger logger = LoggerFactory.getLogger(FlywayDB.class);

    public void check() {
        logger.info("Start database migration");

        final InitialContext cxt;
        final DataSource dataSource;

        try {
            cxt = new InitialContext();
            dataSource = (DataSource) cxt.lookup("java:/comp/env/jdbc/cosmic");
        } catch (final NamingException e) {
            logger.error(e.getMessage(), e);
            throw new CloudRuntimeException(e.getMessage(), e);
        }

        final Flyway flyway = new Flyway();
        flyway.setDataSource(dataSource);
        flyway.setTable("schema_version");
        flyway.setEncoding("UTF-8");

        try {
            flyway.migrate();
        } catch (final FlywayException e) {
            logger.error(e.getMessage(), e);
            throw new CloudRuntimeException(e.getMessage(), e);
        }

        logger.info("Database migration successful");
    }
}

@@ -87,245 +87,310 @@
 on;%0A
-import org.flywaydb.core.Flyway;%0Aimport org.flywaydb.core.api.FlywayException;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport javax.naming.InitialContext;%0Aimport javax.naming.NamingException;%0Aimport javax.sql.DataSource
+%0Aimport javax.naming.InitialContext;%0Aimport javax.naming.NamingException;%0Aimport javax.sql.DataSource;%0A%0Aimport org.flywaydb.core.Flyway;%0Aimport org.flywaydb.core.api.FlywayException;%0Aimport org.flywaydb.core.api.configuration.FluentConfiguration;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
 ;%0A%0Ap
@@ -962,19 +962,38 @@
 l Fl
-yway
+uentConfiguration
  flyway
+Config
  = n
@@ -1001,15 +1001,27 @@
 w Fl
-yway
+uentConfiguration
 ()
-;
 %0A   
@@ -1029,19 +1029,53 @@
     
-flyway.setD
+        .encoding(%22UTF-8%22)%0A                .d
 ataS
@@ -1091,17 +1091,16 @@
 aSource)
-;
 %0A       
@@ -1104,19 +1104,18 @@
     
-flyway.setT
+        .t
 able
@@ -1147,33 +1147,52 @@
    f
-lyway.setEncoding(%22UTF-8%22
+inal Flyway flyway = new Flyway(flywayConfig
 );%0A%0A

Change deprecated flyway methods to new FluentConfiguration