Last active
March 28, 2019 05:42
-
-
Save leapingbytes/fb50fd29c51edbac1cc5bf9e061504bb to your computer and use it in GitHub Desktop.
H2 (MySQL) + Flyway + Sql20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package co.vgw.pok.customer.persistence.sql20; | |
import java.sql.SQLException; | |
import org.flywaydb.core.Flyway; | |
import org.flywaydb.core.api.configuration.FluentConfiguration; | |
import org.h2.tools.Server; | |
import org.sql2o.Sql2o; | |
public abstract class AbstractSql2oTestBase { | |
private static final String JDBC_URL = "jdbc:h2:mem:db_name;MODE=MySQL;DB_CLOSE_DELAY=-1"; | |
private static Server server; | |
protected static Sql2o sql2o; | |
public static void setup() throws SQLException { | |
server = Server.createTcpServer(); | |
FluentConfiguration flyWayConfiguration = new FluentConfiguration() | |
.locations("classpath:/sql") | |
.dataSource(JDBC_URL, "sa", ""); | |
Flyway flyway = new Flyway(flyWayConfiguration); | |
flyway.migrate(); | |
org.h2.jdbcx.JdbcDataSource datasource = new org.h2.jdbcx.JdbcDataSource(); | |
datasource.setURL(JDBC_URL); | |
datasource.setUser("sa"); | |
datasource.setPassword(""); | |
sql2o = new Sql2o(datasource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Highlights
"jdbc:h2:mem:db_name;MODE=MySQL;DB_CLOSE_DELAY=-1";
JDBC_URL.locations("classpath:/sql")
locations tell Flyway where to look for migration files. Use "normal" maven/gradle magic to get the fils into test class pathnew Sql2o(datasource)
Sql2o Sql2o does not understand H2 URL for some reason... but luckily you can create Sql2o object with datasource.