-
Notifications
You must be signed in to change notification settings - Fork 5
[WIP] Refactor jdbc migration and use service loader #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
13f69b0
4180c7b
4c0e7cf
33a356c
cb73cd9
58d893f
452a16e
ee3eeb6
f51f437
fbf4e5f
a405ce0
bc51a45
a66a434
16aee17
e60e475
4da3958
2ab8ef2
40d6a73
3de01dc
6d14cf8
4391093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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>14.0.1-SNAPSHOT</version> | ||
|
|
||
| <scm> | ||
| <developerConnection>scm:git:git@github.com: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>14.0.1-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> |
| 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(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package io.ebean.migration.db; | ||
|
|
||
| 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()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CHECKME: Ebean transfers some values form the DatabaseConfig Would mean that some properties have to be migrated |
||
| this.server = server; | ||
| if (server.config().isRunMigration() && config.isPluginRun()) { | ||
| throw new UnsupportedOperationException("You cannot enable both 'migration.run' and 'migration.plugin.run'"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void online(boolean online) { | ||
| if (online && config.isPluginRun()) { | ||
| new MigrationRunnerDb(config, server).run(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CHECKME: online might be too early. If we decide to implement this as plugin we might need some lifecycles in the Plugin api (e.g. a |
||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void shutdown() { | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| 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; | ||
|
|
||
| /** | ||
| * Runs the default checkState and run method on a current ebean server. | ||
| * | ||
| * @author Roland Praml, FOCONIS AG | ||
| */ | ||
| public class MigrationRunnerDb extends MigrationRunner { | ||
| private final Database db; | ||
|
|
||
| public MigrationRunnerDb(MigrationConfig migrationConfig, Database db) { | ||
| super(migrationConfig); | ||
| this.db = db; | ||
| } | ||
|
|
||
| /** | ||
| * Return the migrations that would be applied if the migration is run. | ||
| */ | ||
| @Override | ||
| public List<MigrationResource> checkState() { | ||
| try (Transaction txn = db.beginTransaction()) { | ||
| return checkState(new TransactionBasedMigrationContext(migrationConfig, txn, db)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Run the migrations if there are any that need running. | ||
| */ | ||
| @Override | ||
| public void run() { | ||
| try (Transaction txn = db.beginTransaction()) { | ||
| run(new TransactionBasedMigrationContext(migrationConfig, txn, db)); | ||
| // No commit here! | ||
| } | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| 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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| io.ebean.migration.db.MigrationPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHECKME: Should I add "Transaction" and "Database" in MigrationContext (means that ebean-migration will get a dependency to ebean-api)