Package migratedb.v1.core.api.migration
Class ScriptMigration
- java.lang.Object
-
- migratedb.v1.core.api.migration.BaseJavaMigration
-
- migratedb.v1.core.api.migration.ScriptMigration
-
- All Implemented Interfaces:
JavaMigration
public abstract class ScriptMigration extends BaseJavaMigration
An easy way to define SQL migration scripts as code. This can eliminate the need for build-time class path scanning when used withFluentConfiguration.javaMigrations(JavaMigration...). Example:@Componentpublic class V009__Add_Cool_Stuff extends ScriptMigration { protected Object script() { return """ -- Add cool stuff create table cool_stuff(id int primary key); insert into cool_stuff(id) values (${cool_id}); drop table old_stuff; """; } }}Computes a checksum from the script contents by default, just like MigrateDB does for migration scripts. You can turn this off by overriding
getChecksum(Configuration).
-
-
Constructor Summary
Constructors Constructor Description ScriptMigration()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ChecksumgetChecksum(Configuration configuration)voidmigrate(Context context)Executes this migration.protected abstract Objectscript()Provides the script to execute.-
Methods inherited from class migratedb.v1.core.api.migration.BaseJavaMigration
canExecuteInTransaction, getDescription, getVersion, isBaselineMigration
-
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
-
-
-
-
Method Detail
-
script
protected abstract Object script()
Provides the script to execute. If this returns aReader, its lines are executed and the reader is properly closed. Everything else is converted to a String viaObject.toString().
-
getChecksum
public Checksum getChecksum(Configuration configuration)
- Returns:
- The checksum of this migration,
nullto disable checksum verification.
-
migrate
public final void migrate(Context context) throws Exception
Description copied from interface:JavaMigrationExecutes 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.
-
-