-
Notifications
You must be signed in to change notification settings - Fork 5
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
Introduce MigrationContext to be prepared for JDBC migration refactor #152
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
ebean-migration/src/main/java/io/ebean/migration/MigrationContext.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,41 @@ | ||
package io.ebean.migration; | ||
|
||
import java.sql.Connection; | ||
|
||
/** | ||
* The current context while a migration runs. | ||
* <p> | ||
* This is used to provide meta-informations in JDBC migrations and mainly provides a read-only access | ||
* to a subset of MigrationConfig. | ||
* <p> | ||
* It is possible to provide an extended implementation in <code>MigrationEngine.run(context)</code>, | ||
* which is accessible in JdbcMigration. So you can create a EbeanMigrationContext, so that you can | ||
* access the current ebean server in the JDBC migration. | ||
* | ||
* @author Roland Praml, FOCONIS AG | ||
*/ | ||
public interface MigrationContext { | ||
/** | ||
* The current connection. Note: During migration, this connection is always the same. | ||
* You must not close this connection! | ||
*/ | ||
Connection connection(); | ||
|
||
/** | ||
* The migration path of SQL migrations. You can use this, to load additional SQL resources | ||
* in your JDBC migration or determine, if this JDBC migration is for a particular path. | ||
* This can be used if you have multiple ebean servers for different databases. | ||
*/ | ||
String migrationPath(); | ||
|
||
/** | ||
* The platform of the current migration run. (e.g. <code>sqlserver17</code>) | ||
*/ | ||
String platform(); | ||
|
||
/** | ||
* The base platform of the current migration run. (e.g. <code>sqlserver</code>) | ||
*/ | ||
String basePlatform(); | ||
|
||
} |
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
45 changes: 45 additions & 0 deletions
45
ebean-migration/src/main/java/io/ebean/migration/runner/DefaultMigrationContext.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,45 @@ | ||
package io.ebean.migration.runner; | ||
|
||
import io.ebean.migration.MigrationConfig; | ||
import io.ebean.migration.MigrationContext; | ||
|
||
import java.sql.Connection; | ||
|
||
/** | ||
* A default implementation of the MigrationContext. | ||
* | ||
* @author Roland Praml, FOCONIS AG | ||
*/ | ||
public class DefaultMigrationContext implements MigrationContext { | ||
private final Connection connection; | ||
private final String migrationPath; | ||
private final String platform; | ||
private final String basePlatform; | ||
|
||
public DefaultMigrationContext(MigrationConfig config, Connection connection) { | ||
this.connection = connection; | ||
this.migrationPath = config.getMigrationPath(); | ||
this.platform = config.getPlatform(); | ||
this.basePlatform = config.getBasePlatform(); | ||
} | ||
|
||
@Override | ||
public Connection connection() { | ||
return connection; | ||
} | ||
|
||
@Override | ||
public String migrationPath() { | ||
return migrationPath; | ||
} | ||
|
||
@Override | ||
public String platform() { | ||
return platform; | ||
} | ||
|
||
@Override | ||
public String basePlatform() { | ||
return basePlatform; | ||
} | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be great, if ebean-migration can have a dependency to have access to "Database". What do you think about this idea?
Otherwise, I plan to imlement a EbeanMigrationContext extends DefaultMigrationContext, that has a
Database getDb()
method in our application and cast to this context in our JdbcMigrationsThere 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.
Yes, I would expect it along with a ebean Transaction - so with Database and Transaction then Jdbc Migrations can use all the features of ebean etc.
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.
Note that I don't expect this DefaultMigrationContext to be public.