diff --git a/ebean-migration-db/pom.xml b/ebean-migration-db/pom.xml
new file mode 100644
index 0000000..2e57eb1
--- /dev/null
+++ b/ebean-migration-db/pom.xml
@@ -0,0 +1,169 @@
+
+
+ 4.0.0
+
+ org.avaje
+ java11-oss
+ 3.12
+
+
+
+ io.ebean
+ ebean-migration-db
+ 13.11.2-SNAPSHOT
+
+
+ scm:git:git@github.com:ebean-orm/ebean-migration.git
+ HEAD
+
+
+
+ true
+ false
+
+
+
+
+
+ io.ebean
+ ebean-migration
+ 13.11.2-SNAPSHOT
+
+
+
+ io.ebean
+ ebean-api
+ 13.25.0
+ provided
+
+
+
+
+ io.avaje
+ classpath-scanner
+ 7.1
+
+
+
+
+ io.ebean
+ ebean
+ 13.25.0
+ test
+
+
+
+ com.h2database
+ h2
+ 2.2.220
+ test
+
+
+
+ com.microsoft.sqlserver
+ mssql-jdbc
+ 9.4.1.jre8
+ test
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.28
+ test
+
+
+
+ org.postgresql
+ postgresql
+ 42.4.3
+ test
+
+
+
+ com.nuodb.jdbc
+ nuodb-jdbc
+ 22.0.0
+ test
+
+
+
+ com.ibm.db2
+ jcc
+ 11.5.6.0
+ test
+
+
+
+ org.mariadb.jdbc
+ mariadb-java-client
+ 3.0.6
+ test
+
+
+
+ com.oracle.database.jdbc
+
+ ojdbc8
+ 19.12.0.0
+ test
+
+
+
+
+
+
+
+
+
+
+
+ org.avaje.composite
+ logback
+ 1.1
+ test
+
+
+
+ io.ebean
+ ebean-test-containers
+ 7.1
+ test
+
+
+
+ io.avaje
+ junit
+ 1.3
+ test
+
+
+
+ io.ebean
+ ebean-datasource
+ 8.0
+ test
+
+
+
+
+
+
+ io.repaint.maven
+ tiles-maven-plugin
+ 2.33
+ true
+
+
+ io.ebean.tile:enhancement:13.25.0
+
+
+
+
+
+
diff --git a/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationContextDb.java b/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationContextDb.java
new file mode 100644
index 0000000..214becb
--- /dev/null
+++ b/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationContextDb.java
@@ -0,0 +1,14 @@
+package io.ebean.migration.db;
+
+import io.ebean.Database;
+import io.ebean.Transaction;
+import io.ebean.migration.MigrationContext;
+
+/**
+ * @author Roland Praml, FOCONIS AG
+ */
+public interface MigrationContextDb extends MigrationContext {
+ public Transaction transaction();
+
+ public Database database();
+}
diff --git a/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationPlugin.java b/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationPlugin.java
new file mode 100644
index 0000000..2e28e56
--- /dev/null
+++ b/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationPlugin.java
@@ -0,0 +1,37 @@
+package io.ebean.migration.db;
+
+import io.ebean.DB;
+import io.ebean.Database;
+import io.ebean.migration.MigrationConfig;
+import io.ebean.plugin.Plugin;
+import io.ebean.plugin.SpiServer;
+
+/**
+ * @author Roland Praml, FOCONIS AG
+ */
+public class MigrationPlugin implements Plugin {
+ private MigrationConfig config = new MigrationConfig();
+ private SpiServer server;
+
+ @Override
+ public void configure(SpiServer server) {
+ config.setName(server.name());
+ config.load(server.config().getProperties());
+ this.server = server;
+ if (server.config().isRunMigration() && config.isAutoRun()) {
+ throw new UnsupportedOperationException("You cannot enable both"); // TODO
+ }
+ }
+
+ @Override
+ public void online(boolean online) {
+ if (online && config.isAutoRun()) {
+ new MigrationRunnerDb(config).run(server);
+ }
+ }
+
+ @Override
+ public void shutdown() {
+
+ }
+}
diff --git a/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationRunnerDb.java b/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationRunnerDb.java
new file mode 100644
index 0000000..362a680
--- /dev/null
+++ b/ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationRunnerDb.java
@@ -0,0 +1,38 @@
+package io.ebean.migration.db;
+
+import io.ebean.Database;
+import io.ebean.Transaction;
+import io.ebean.migration.MigrationConfig;
+import io.ebean.migration.MigrationResource;
+import io.ebean.migration.MigrationRunner;
+
+import java.util.List;
+
+
+/**
+ * @author Roland Praml, FOCONIS AG
+ */
+public class MigrationRunnerDb extends MigrationRunner {
+ public MigrationRunnerDb(MigrationConfig migrationConfig) {
+ super(migrationConfig);
+ }
+
+ /**
+ * Return the migrations that would be applied if the migration is run.
+ */
+ public List checkState(Database db) {
+ try (Transaction txn = db.beginTransaction()) {
+ return checkState(new TransactionBasedMigrationContext(migrationConfig, txn, db));
+ }
+ }
+
+ /**
+ * Run the migrations if there are any that need running.
+ */
+ public void run(Database db) {
+ try (Transaction txn = db.beginTransaction()) {
+ run(new TransactionBasedMigrationContext(migrationConfig, txn, db));
+ txn.end();
+ }
+ }
+}
diff --git a/ebean-migration-db/src/main/java/io/ebean/migration/db/TransactionBasedMigrationContext.java b/ebean-migration-db/src/main/java/io/ebean/migration/db/TransactionBasedMigrationContext.java
new file mode 100644
index 0000000..4c5dda9
--- /dev/null
+++ b/ebean-migration-db/src/main/java/io/ebean/migration/db/TransactionBasedMigrationContext.java
@@ -0,0 +1,66 @@
+package io.ebean.migration.db;
+
+import io.ebean.Database;
+import io.ebean.Transaction;
+import io.ebean.migration.MigrationConfig;
+import io.ebean.migration.MigrationContext;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * A default implementation of the MigrationContext.
+ *
+ * @author Roland Praml, FOCONIS AG
+ */
+class TransactionBasedMigrationContext implements MigrationContextDb {
+ private final Transaction transaction;
+ private final String migrationPath;
+ private final String platform;
+ private final String basePlatform;
+ private final Database database;
+
+ TransactionBasedMigrationContext(MigrationConfig config, Transaction transaction, Database database) {
+ this.transaction = transaction;
+ this.migrationPath = config.getMigrationPath();
+ this.platform = config.getPlatform();
+ this.basePlatform = config.getBasePlatform();
+ this.database = database;
+ }
+
+ @Override
+ public Connection connection() {
+ return transaction.connection();
+ }
+
+ @Override
+ public String migrationPath() {
+ return migrationPath;
+ }
+
+ @Override
+ public String platform() {
+ return platform;
+ }
+
+ @Override
+ public String basePlatform() {
+ return basePlatform;
+ }
+
+ @Override
+ public void commit() throws SQLException {
+ // we must not use txn.commit here, as this closes the underlying connection, which is needed for logicalLock etc.
+ transaction.commitAndContinue();
+ }
+
+ @Override
+ public Transaction transaction() {
+ return transaction;
+ }
+
+ @Override
+ public Database database() {
+ return database;
+ }
+}
diff --git a/ebean-migration-db/src/main/java/module-info.java b/ebean-migration-db/src/main/java/module-info.java
new file mode 100644
index 0000000..15e0a6b
--- /dev/null
+++ b/ebean-migration-db/src/main/java/module-info.java
@@ -0,0 +1,13 @@
+module io.ebean.migration.db {
+
+ exports io.ebean.migration.db;
+
+ requires transitive java.sql;
+ requires transitive io.avaje.applog;
+ requires transitive io.avaje.classpath.scanner;
+ requires transitive io.ebean.ddl.runner;
+ requires static io.ebean.api;
+ requires io.ebean.migration;
+ uses io.ebean.plugin.Plugin;
+ provides io.ebean.plugin.Plugin with io.ebean.migration.db.MigrationPlugin;
+}
diff --git a/ebean-migration-db/src/main/resources/META-INF/services/io.ebean.plugin.Plugin b/ebean-migration-db/src/main/resources/META-INF/services/io.ebean.plugin.Plugin
new file mode 100644
index 0000000..df259f8
--- /dev/null
+++ b/ebean-migration-db/src/main/resources/META-INF/services/io.ebean.plugin.Plugin
@@ -0,0 +1 @@
+io.ebean.migration.db.MigrationPlugin
diff --git a/ebean-migration-db/src/test/java/io/ebean/migration/it/EbeanMigrationTest.java b/ebean-migration-db/src/test/java/io/ebean/migration/it/EbeanMigrationTest.java
new file mode 100644
index 0000000..14287da
--- /dev/null
+++ b/ebean-migration-db/src/test/java/io/ebean/migration/it/EbeanMigrationTest.java
@@ -0,0 +1,85 @@
+package io.ebean.migration.it;
+
+import io.ebean.DB;
+import io.ebean.Database;
+import io.ebean.DatabaseFactory;
+import io.ebean.config.DatabaseConfig;
+import io.ebean.migration.MigrationConfig;
+import io.ebean.migration.MigrationRunner;
+import io.ebean.migration.db.MigrationRunnerDb;
+import org.migration.model.M3;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Roland Praml, FOCONIS AG
+ */
+public class EbeanMigrationTest {
+
+ @Test
+ public void testEbeanServerJdbcMig() {
+
+ // NOTE: This can be done by AutoMigration (or MigrationPlugin) later
+ MigrationConfig config = new MigrationConfig();
+ Database db = DB.getDefault();
+ try {
+ config.setName(db.name());
+ config.load(db.pluginApi().config().getProperties());
+ new MigrationRunnerDb(config).run(db);
+
+
+ M3 m3 = DB.find(M3.class).where().idEq(1).findOne();
+ assertThat(m3.getAcol()).isEqualTo("Migrate db PreCommit");
+ } finally {
+ db.shutdown(true, false);
+ }
+ }
+
+ @Test
+ public void testWithRunner() {
+
+ // NOTE: This can be done by AutoMigration (or MigrationPlugin) later
+ DatabaseConfig dbCfg = new DatabaseConfig();
+ dbCfg.setName("h2");
+ dbCfg.loadFromProperties();
+ dbCfg.setRunMigration(true);
+ Database db = DatabaseFactory.create(dbCfg);
+ try {
+
+ M3 m3 = DB.find(M3.class).where().idEq(1).findOne();
+ assertThat(m3.getAcol()).isEqualTo("Migrate raw");
+ } finally {
+ db.shutdown(true, false);
+ }
+
+ }
+
+ @Test
+ public void testNoMigration() {
+ Database db = DB.getDefault();
+ try {
+
+ M3 m3 = DB.find(M3.class).where().idEq(1).findOne();
+ assertThat(m3.getAcol()).isEqualTo("Migrate db PreCommit");
+ } finally {
+ db.shutdown(true, false);
+ }
+ }
+ @Test
+ public void testWithPlugin() {
+ DatabaseConfig dbCfg = new DatabaseConfig();
+ dbCfg.setName("h2");
+ dbCfg.loadFromProperties();
+ dbCfg.getProperties().setProperty("ebean.h2.migration.autoRun", "true");
+ dbCfg.setDefaultServer(true);
+ Database db = DatabaseFactory.create(dbCfg);
+ try {
+
+ M3 m3 = DB.find(M3.class).where().idEq(1).findOne();
+ assertThat(m3.getAcol()).isEqualTo("Migrate db PreCommit");
+ } finally {
+ db.shutdown(true, false);
+ }
+ }
+}
diff --git a/ebean-migration-db/src/test/java/io/ebean/migration/it/V1_2_1__test.java b/ebean-migration-db/src/test/java/io/ebean/migration/it/V1_2_1__test.java
new file mode 100644
index 0000000..520316e
--- /dev/null
+++ b/ebean-migration-db/src/test/java/io/ebean/migration/it/V1_2_1__test.java
@@ -0,0 +1,57 @@
+package io.ebean.migration.it;
+
+import io.ebean.DB;
+import io.ebean.Database;
+import io.ebean.Transaction;
+import io.ebean.TxScope;
+import io.ebean.migration.JdbcMigration;
+import io.ebean.migration.MigrationContext;
+import io.ebean.migration.db.MigrationContextDb;
+import io.ebeaninternal.server.core.DefaultServer;
+import io.ebeaninternal.server.transaction.ExternalJdbcTransaction;
+import io.ebeaninternal.server.transaction.TransactionManager;
+import org.migration.model.M3;
+
+import javax.persistence.PersistenceException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+import static org.assertj.core.api.Assertions.assertThat;
+/**
+ * Sample migration.
+ *
+ * @author Roland Praml, FOCONIS AG
+ */
+public class V1_2_1__test implements JdbcMigration {
+
+
+ @Override
+ public void migrate(MigrationContext context) throws SQLException {
+ if (context instanceof MigrationContextDb) {
+ // some asserts
+ Database db = ((MigrationContextDb) context).database(); // do not use DB.getDefault, as it is not yet registered!
+
+ assertThat(((MigrationContextDb) context).transaction())
+ .isNotNull()
+ .isSameAs(db.currentTransaction());
+
+ M3 m3 = db.find(M3.class).where().idEq(1).findOne();
+ m3.setAcol("Migrate db");
+ db.save(m3);
+
+ } else {
+ try (PreparedStatement ps = context.connection().prepareStatement("update m3 set acol = ? where id = ?")) {
+ ps.setString(1, "Migrate raw");
+ ps.setInt(2, 1);
+ ps.executeUpdate();
+ }
+ }
+ }
+
+
+ @Override
+ public String toString() {
+ return "Dummy jdbc migration";
+ }
+}
diff --git a/ebean-migration-it/src/main/java/org/migration/model/M3.java b/ebean-migration-db/src/test/java/org/migration/model/M3.java
similarity index 67%
rename from ebean-migration-it/src/main/java/org/migration/model/M3.java
rename to ebean-migration-db/src/test/java/org/migration/model/M3.java
index 9c4eca6..500e2ff 100644
--- a/ebean-migration-it/src/main/java/org/migration/model/M3.java
+++ b/ebean-migration-db/src/test/java/org/migration/model/M3.java
@@ -1,7 +1,8 @@
package org.migration.model;
-import jakarta.persistence.Entity;
-import jakarta.persistence.Id;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.PreUpdate;
/**
* @author Roland Praml, FOCONIS AG
@@ -27,4 +28,9 @@ public String getAcol() {
public void setAcol(String acol) {
this.acol = acol;
}
+
+ @PreUpdate
+ public void addCommitMsg() {
+ acol += " PreCommit";
+ }
}
diff --git a/ebean-migration-db/src/test/resources/dbmig/1.1__initial.sql b/ebean-migration-db/src/test/resources/dbmig/1.1__initial.sql
new file mode 100644
index 0000000..c627009
--- /dev/null
+++ b/ebean-migration-db/src/test/resources/dbmig/1.1__initial.sql
@@ -0,0 +1,5 @@
+create table m1 (id integer, acol varchar(20));
+-- Check with DB2:
+-- call sysproc.admin_cmd('reorg table m1');
+create table m2 (id integer, acol varchar(20), bcol timestamp);
+
diff --git a/ebean-migration-db/src/test/resources/dbmig/1.2__add_m3.sql b/ebean-migration-db/src/test/resources/dbmig/1.2__add_m3.sql
new file mode 100644
index 0000000..3518305
--- /dev/null
+++ b/ebean-migration-db/src/test/resources/dbmig/1.2__add_m3.sql
@@ -0,0 +1,5 @@
+create table m3 (id integer, acol varchar(20), bcol timestamp);
+
+alter table m1 add column addcol varchar(10);
+
+insert into m3 (id, acol) VALUES (1, 'text with ; sign'); -- plus some comment
diff --git a/ebean-migration-db/src/test/resources/dbmig/I__hello.sql b/ebean-migration-db/src/test/resources/dbmig/I__hello.sql
new file mode 100644
index 0000000..63a4934
--- /dev/null
+++ b/ebean-migration-db/src/test/resources/dbmig/I__hello.sql
@@ -0,0 +1 @@
+-- do nothing
diff --git a/ebean-migration-db/src/test/resources/dbmig/R__m2_view.sql b/ebean-migration-db/src/test/resources/dbmig/R__m2_view.sql
new file mode 100644
index 0000000..6a7c4df
--- /dev/null
+++ b/ebean-migration-db/src/test/resources/dbmig/R__m2_view.sql
@@ -0,0 +1 @@
+create or replace view m2_vw as select id, acol from m2;
diff --git a/ebean-migration-db/src/test/resources/ebean.properties b/ebean-migration-db/src/test/resources/ebean.properties
new file mode 100644
index 0000000..1047822
--- /dev/null
+++ b/ebean-migration-db/src/test/resources/ebean.properties
@@ -0,0 +1,12 @@
+ebean.ddl.generate=false
+ebean.ddl.run=false
+
+ebean.packages=org.migration.model
+
+datasource.default=h2
+datasource.h2.username=sa
+datasource.h2.password=
+datasource.h2.url=jdbc:h2:mem:testsMem;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=KEY,VALUE
+
+ebean.h2.migration.migrationPath=dbmig
+ebean.h2.migration.jdbcMigrations=io.ebean.migration.it.V1_2_1__test
diff --git a/ebean-migration-db/src/test/resources/logback-test.xml b/ebean-migration-db/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..a227835
--- /dev/null
+++ b/ebean-migration-db/src/test/resources/logback-test.xml
@@ -0,0 +1,17 @@
+
+
+
+ TRACE
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
diff --git a/ebean-migration-it/src/main/java/org/migration/model/DemoModel.java b/ebean-migration-it/src/main/java/org/migration/model/DemoModel.java
deleted file mode 100644
index a0274d1..0000000
--- a/ebean-migration-it/src/main/java/org/migration/model/DemoModel.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.migration.model;
-
-import jakarta.persistence.Entity;
-import jakarta.persistence.Id;
-
-/**
- * @author Roland Praml, FOCONIS AG
- */
-@Entity
-public class DemoModel {
- @Id
- private int id;
-
- private String foo;
-}
diff --git a/ebean-migration-it/src/test/java/io/ebean/migration/it/EbeanMigrationTest.java b/ebean-migration-it/src/test/java/io/ebean/migration/it/EbeanMigrationTest.java
index d9658ae..0cf7781 100644
--- a/ebean-migration-it/src/test/java/io/ebean/migration/it/EbeanMigrationTest.java
+++ b/ebean-migration-it/src/test/java/io/ebean/migration/it/EbeanMigrationTest.java
@@ -5,7 +5,6 @@
import io.ebean.DatabaseFactory;
import io.ebean.config.DatabaseConfig;
import io.ebean.migration.MigrationConfig;
-import io.ebean.migration.MigrationRunner;
import org.migration.model.M3;
import org.junit.jupiter.api.Test;
diff --git a/ebean-migration-it/src/test/java/io/ebean/migration/it/V1_2_1__test.java b/ebean-migration-it/src/test/java/io/ebean/migration/it/V1_2_1__test.java
index 8eaa75c..943b1aa 100644
--- a/ebean-migration-it/src/test/java/io/ebean/migration/it/V1_2_1__test.java
+++ b/ebean-migration-it/src/test/java/io/ebean/migration/it/V1_2_1__test.java
@@ -5,9 +5,6 @@
import io.ebean.TxScope;
import io.ebean.migration.JdbcMigration;
import io.ebean.migration.MigrationContext;
-import io.ebeaninternal.api.ScopeTrans;
-import io.ebeaninternal.api.ScopedTransaction;
-import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.server.core.DefaultServer;
import io.ebeaninternal.server.transaction.ExternalJdbcTransaction;
import io.ebeaninternal.server.transaction.TransactionManager;
diff --git a/ebean-migration/pom.xml b/ebean-migration/pom.xml
index 266aa0e..98636d5 100644
--- a/ebean-migration/pom.xml
+++ b/ebean-migration/pom.xml
@@ -39,7 +39,7 @@
io.ebean
ebean-api
13.25.0
- provided
+ true
@@ -164,4 +164,5 @@ mvn install:install-file -Dfile=/some/path/to/ojdbc7.jar -DgroupId=oracle \
+
diff --git a/ebean-migration/src/main/java/io/ebean/migration/JdbcMigration.java b/ebean-migration/src/main/java/io/ebean/migration/JdbcMigration.java
index 6219412..99bf021 100644
--- a/ebean-migration/src/main/java/io/ebean/migration/JdbcMigration.java
+++ b/ebean-migration/src/main/java/io/ebean/migration/JdbcMigration.java
@@ -1,6 +1,7 @@
package io.ebean.migration;
import java.sql.Connection;
+import java.sql.SQLException;
/**
* Interface to be implemented by Jdbc Java Migrations. By default the migration
@@ -31,7 +32,7 @@ public interface JdbcMigration extends MigrationChecksumProvider {
* Note: This API has changed with ebean-migration 13.12, as the initialization has changed.
* See https://github.com/ebean-orm/ebean-migration/issues/90 for migration advice.
*/
- void migrate(MigrationContext context);
+ void migrate(MigrationContext context) throws SQLException;
@Override
default int getChecksum() {
diff --git a/ebean-migration/src/main/java/io/ebean/migration/MigrationConfig.java b/ebean-migration/src/main/java/io/ebean/migration/MigrationConfig.java
index bb7dd8f..b73a06e 100644
--- a/ebean-migration/src/main/java/io/ebean/migration/MigrationConfig.java
+++ b/ebean-migration/src/main/java/io/ebean/migration/MigrationConfig.java
@@ -37,6 +37,11 @@ public class MigrationConfig {
private boolean setCurrentSchema = true;
private boolean allowErrorInRepeatable;
+ /**
+ * Run migration automatically when ebean starts (Requires MigrationPlugin)
+ */
+ private boolean autoRun;
+
/**
* Holds a Collection/Iterable of JdbcMigrations. All migrations (JDBC and SQL) are
* extecuted in the order defined by their version numbers.
@@ -495,6 +500,20 @@ public void setMinVersionFailMessage(String minVersionFailMessage) {
this.minVersionFailMessage = minVersionFailMessage;
}
+ /**
+ * Sets, if migration should automatically run when ebean starts.
+ */
+ public void setAutoRun(boolean autoRun) {
+ this.autoRun = autoRun;
+ }
+
+ /**
+ * run migration on ebean start
+ */
+ public boolean isAutoRun() {
+ return autoRun;
+ }
+
/**
* Load configuration from standard properties.
*/
@@ -521,6 +540,7 @@ public void load(Properties props) {
runPlaceholders = property("placeholders", runPlaceholders);
minVersion = property("minVersion", minVersion);
minVersionFailMessage = property("minVersionFailMessage", minVersionFailMessage);
+ autoRun = property("autoRun", autoRun);
String jdbcMigrations = property("jdbcMigrations");
if (jdbcMigrations != null) {
diff --git a/ebean-migration/src/main/java/io/ebean/migration/runner/LocalMigrationResources.java b/ebean-migration/src/main/java/io/ebean/migration/runner/LocalMigrationResources.java
index a640021..f082fe4 100644
--- a/ebean-migration/src/main/java/io/ebean/migration/runner/LocalMigrationResources.java
+++ b/ebean-migration/src/main/java/io/ebean/migration/runner/LocalMigrationResources.java
@@ -27,16 +27,14 @@ final class LocalMigrationResources {
private final MigrationConfig migrationConfig;
private final ClassLoader classLoader;
private final Iterable jdbcMigrations;
- private final MigrationContext context;
/**
* Construct with configuration options.
*/
- LocalMigrationResources(MigrationConfig migrationConfig, MigrationContext context) {
+ LocalMigrationResources(MigrationConfig migrationConfig) {
this.migrationConfig = migrationConfig;
this.classLoader = migrationConfig.getClassLoader();
this.jdbcMigrations = migrationConfig.getJdbcMigrations();
- this.context = context;
}
/**
@@ -51,7 +49,7 @@ boolean readInitResources() {
/**
* Read all the migration resources (SQL scripts and JDBC migrations) returning true if there are versions.
*/
- boolean readResources() {
+ boolean readResources(MigrationContext context) {
if (readFromIndex()) {
// automatically enable earlyChecksumMode when using index file with pre-computed checksums
migrationConfig.setEarlyChecksumMode(true);
@@ -60,7 +58,7 @@ boolean readResources() {
}
// after we read the SQL migrations from index or classpath scan, we
// read jdbcMigrations and sort them.
- readJdbcMigrations();
+ readJdbcMigrations(context);
Collections.sort(versions);
return !versions.isEmpty();
}
@@ -92,7 +90,7 @@ private boolean readFromIndex() {
return false;
}
- private void readJdbcMigrations() {
+ private void readJdbcMigrations(MigrationContext context) {
if (jdbcMigrations != null) {
for (JdbcMigration jdbcMigration : jdbcMigrations) {
if (jdbcMigration.matches(context)) {
diff --git a/ebean-migration/src/main/java/io/ebean/migration/runner/MigrationEngine.java b/ebean-migration/src/main/java/io/ebean/migration/runner/MigrationEngine.java
index 8ea04a5..323e7de 100644
--- a/ebean-migration/src/main/java/io/ebean/migration/runner/MigrationEngine.java
+++ b/ebean-migration/src/main/java/io/ebean/migration/runner/MigrationEngine.java
@@ -53,8 +53,8 @@ public List run(Connection connection) {
public List run(MigrationContext context) {
long startMs = System.currentTimeMillis();
- LocalMigrationResources resources = new LocalMigrationResources(migrationConfig, context);
- if (!resources.readResources() && !resources.readInitResources()) {
+ LocalMigrationResources resources = new LocalMigrationResources(migrationConfig);
+ if (!resources.readResources(context) && !resources.readInitResources()) {
log.log(DEBUG, "no migrations to check");
return emptyList();
}
diff --git a/ebean-migration/src/main/java/module-info.java b/ebean-migration/src/main/java/module-info.java
index 2856c9d..e0f8e22 100644
--- a/ebean-migration/src/main/java/module-info.java
+++ b/ebean-migration/src/main/java/module-info.java
@@ -1,13 +1,11 @@
open module io.ebean.migration {
exports io.ebean.migration;
- exports io.ebean.migration.db;
requires transitive java.sql;
requires transitive io.avaje.applog;
requires transitive io.avaje.classpath.scanner;
requires transitive io.ebean.ddl.runner;
- //requires transitive io.ebean.api;
requires io.ebean.migration.auto;
uses io.ebean.migration.JdbcMigration;
diff --git a/pom.xml b/pom.xml
index 2526367..22ef846 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,8 @@
ebean-migration-auto
ebean-migration
- ebean-migration-it
+ ebean-migration-db
+