-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
561 additions
and
34 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.avaje</groupId> | ||
<artifactId>java11-oss</artifactId> | ||
<version>3.12</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-migration-db</artifactId> | ||
<version>13.11.2-SNAPSHOT</version> | ||
|
||
<scm> | ||
<developerConnection>scm:git:[email protected]:ebean-orm/ebean-migration.git</developerConnection> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<properties> | ||
<nexus.staging.autoReleaseAfterClose>true</nexus.staging.autoReleaseAfterClose> | ||
<surefire.useModulePath>false</surefire.useModulePath> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-migration</artifactId> | ||
<version>13.11.2-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-api</artifactId> | ||
<version>13.25.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>classpath-scanner</artifactId> | ||
<version>7.1</version> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean</artifactId> | ||
<version>13.25.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>2.2.220</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.microsoft.sqlserver</groupId> | ||
<artifactId>mssql-jdbc</artifactId> | ||
<version>9.4.1.jre8</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.28</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>42.4.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.nuodb.jdbc</groupId> | ||
<artifactId>nuodb-jdbc</artifactId> | ||
<version>22.0.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.ibm.db2</groupId> | ||
<artifactId>jcc</artifactId> | ||
<version>11.5.6.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mariadb.jdbc</groupId> | ||
<artifactId>mariadb-java-client</artifactId> | ||
<version>3.0.6</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.oracle.database.jdbc</groupId> | ||
<!-- Note: Using ojdbc10 here will affect loading other drivers on jdk8, | ||
because the driverManager will stop on first load error and stops loading | ||
other drivers --> | ||
<artifactId>ojdbc8</artifactId> | ||
<version>19.12.0.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- | ||
mvn install:install-file -Dfile=/some/path/to/ojdbc7.jar -DgroupId=oracle \ | ||
-DartifactId=oracle-jdbc -Dversion=7.0 -Dpackaging=jar | ||
--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>oracle</groupId>--> | ||
<!-- <artifactId>oracle-jdbc</artifactId>--> | ||
<!-- <version>8.0</version>--> | ||
<!-- <scope>test</scope>--> | ||
<!-- </dependency>--> | ||
|
||
<dependency> | ||
<groupId>org.avaje.composite</groupId> | ||
<artifactId>logback</artifactId> | ||
<version>1.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-test-containers</artifactId> | ||
<version>7.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.ebean</groupId> | ||
<artifactId>ebean-datasource</artifactId> | ||
<version>8.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.repaint.maven</groupId> | ||
<artifactId>tiles-maven-plugin</artifactId> | ||
<version>2.33</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<tiles> | ||
<tile>io.ebean.tile:enhancement:13.25.0</tile> | ||
</tiles> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
14 changes: 14 additions & 0 deletions
14
ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationContextDb.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
37 changes: 37 additions & 0 deletions
37
ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationPlugin.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
ebean-migration-db/src/main/java/io/ebean/migration/db/MigrationRunnerDb.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MigrationResource> 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(); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
ebean-migration-db/src/main/java/io/ebean/migration/db/TransactionBasedMigrationContext.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
1 change: 1 addition & 0 deletions
1
ebean-migration-db/src/main/resources/META-INF/services/io.ebean.plugin.Plugin
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.ebean.migration.db.MigrationPlugin |
Oops, something went wrong.