Package com.coditory.sherlock
Class SherlockMigrator
- java.lang.Object
-
- com.coditory.sherlock.SherlockMigrator
-
public final class SherlockMigrator extends java.lang.Object
Migration mechanism based onSherlock
distributed locks.It can be used to perform one way database migrations.
Migration rules:
- migrations must not run in parallel
- migration change sets are applied in order
- migration change sets must be run only once per all migrations
- migration process stops after first change set failure
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SherlockMigrator.MigrationResult
-
Constructor Summary
Constructors Constructor Description SherlockMigrator(Sherlock sherlock)
SherlockMigrator(java.lang.String migrationId, Sherlock sherlock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SherlockMigrator
addChangeSet(java.lang.String changeSetId, java.lang.Runnable changeSet)
Adds change set to migration process.SherlockMigrator.MigrationResult
migrate()
Runs the migration process.
-
-
-
Constructor Detail
-
SherlockMigrator
public SherlockMigrator(Sherlock sherlock)
- Parameters:
sherlock
- sherlock used to manage migration locks
-
SherlockMigrator
public SherlockMigrator(java.lang.String migrationId, Sherlock sherlock)
- Parameters:
migrationId
- id used as lock id for the whole migration processsherlock
- sherlock used to manage migration locks
-
-
Method Detail
-
addChangeSet
public SherlockMigrator addChangeSet(java.lang.String changeSetId, java.lang.Runnable changeSet)
Adds change set to migration process.- Parameters:
changeSetId
- unique change set id used. This is is used as a lock id in migration process.changeSet
- change set action that should be run if change set was not already applied- Returns:
- the migrator
-
migrate
public SherlockMigrator.MigrationResult migrate()
Runs the migration process.- Returns:
- migration result
-
-