Package migratedb.v1.core.api.migration
Interface JavaMigration
-
- All Known Implementing Classes:
BaseJavaMigration,ScriptMigration
public interface JavaMigrationInterface to be implemented by Java-based Migrations.Java-based migrations are a great fit for all changes that can not easily be expressed using SQL.
These would typically be things like
- BLOB & CLOB changes
- Advanced bulk data changes (Recalculations, advanced format changes, …)
Migration classes implementing this interface will be automatically discovered when placed in a location on the classpath.
Most users will be better served by subclassing subclass
BaseJavaMigrationinstead of implementing this interface directly, asBaseJavaMigrationencourages the use of MigrateDB 's default naming convention and comes with sensible default implementations of all methods (except migrate of course) while at the same time also providing better isolation against future additions to this interface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description booleancanExecuteInTransaction()Whether the execution should take place inside a transaction.default @Nullable IntegergetChecksum()Deprecated, for removal: This API element is subject to removal in a future version.ImplementgetChecksum(Configuration)instead.default @Nullable ChecksumgetChecksum(Configuration configuration)StringgetDescription()@Nullable VersiongetVersion()booleanisBaselineMigration()Whether this is a baseline migration.voidmigrate(Context context)Executes this migration.
-
-
-
Method Detail
-
getVersion
@Nullable Version getVersion()
- Returns:
- The version of the schema after the migration is complete.
nullfor repeatable migrations.
-
getDescription
String getDescription()
- Returns:
- The description of this migration for the migration history. Never
null.
-
getChecksum
@Deprecated(forRemoval=true) default @Nullable Integer getChecksum()
Deprecated, for removal: This API element is subject to removal in a future version.ImplementgetChecksum(Configuration)instead.- Returns:
- The checksum of this migration.
-
getChecksum
default @Nullable Checksum getChecksum(Configuration configuration)
- Returns:
- The checksum of this migration,
nullto disable checksum verification.
-
isBaselineMigration
boolean isBaselineMigration()
Whether this is a baseline migration.- Returns:
trueif it is,falseif not.
-
canExecuteInTransaction
boolean canExecuteInTransaction()
Whether the execution should take place inside a transaction. Almost all implementations should returntrue. This however makes it possible to execute certain migrations outside a transaction. This is useful for databases like PostgreSQL and SQL Server where certain statement can only execute outside a transaction.- Returns:
trueif a transaction should be used (highly recommended), orfalseif not.
-
migrate
void migrate(Context context) throws Exception
Executes this migration. The execution will automatically take place within a transaction, when the underlying database supports it and the canExecuteInTransaction returnstrue.- Parameters:
context- The context relevant for this migration, containing things like the JDBC connection to use and the current MigrateDB configuration.- Throws:
Exception- when the migration failed.
-
-