Package migratedb.v1.core.api.migration
Class BaseJavaMigration
- java.lang.Object
-
- migratedb.v1.core.api.migration.BaseJavaMigration
-
- All Implemented Interfaces:
JavaMigration
- Direct Known Subclasses:
ScriptMigration
public abstract class BaseJavaMigration extends Object implements JavaMigration
This is the recommended class to extend for implementing Java-based Migrations.
Subclasses should follow the default MigrateDB naming convention of having a class name with the following structure:
- Versioned Migrations: V2__Add_new_table
- Repeatable Migrations: R__Add_new_table
- Baseline Migrations: B2__Add_new_table
The file name consists of the following parts:
- Prefix: V for versioned migrations, R for repeatable migrations, B for baseline migrations
- Version: Underscores (automatically replaced by dots at runtime) separate as many parts as you like (Not for repeatable migrations)
- Separator: __ (two underscores)
- Description: Underscores (automatically replaced by spaces at runtime) separate the words
If you need more control over the class name, you can override the default convention by implementing the JavaMigration interface directly. This will allow you to name your class as you wish. Version, description and migration category are provided by implementing the respective methods.
-
-
Constructor Summary
Constructors Constructor Description BaseJavaMigration()Creates a new instance of a Java-based migration following MigrateDB's default naming convention.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanExecuteInTransaction()Whether the execution should take place inside a transaction.StringgetDescription()VersiongetVersion()booleanisBaselineMigration()Whether this is a baseline migration.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface migratedb.v1.core.api.migration.JavaMigration
getChecksum, getChecksum, migrate
-
-
-
-
Method Detail
-
getVersion
public final Version getVersion()
- Specified by:
getVersionin interfaceJavaMigration- Returns:
- The version of the schema after the migration is complete.
nullfor repeatable migrations.
-
getDescription
public final String getDescription()
- Specified by:
getDescriptionin interfaceJavaMigration- Returns:
- The description of this migration for the migration history. Never
null.
-
isBaselineMigration
public final boolean isBaselineMigration()
Description copied from interface:JavaMigrationWhether this is a baseline migration.- Specified by:
isBaselineMigrationin interfaceJavaMigration- Returns:
trueif it is,falseif not.
-
canExecuteInTransaction
public boolean canExecuteInTransaction()
Description copied from interface:JavaMigrationWhether 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.- Specified by:
canExecuteInTransactionin interfaceJavaMigration- Returns:
trueif a transaction should be used (highly recommended), orfalseif not.
-
-