Class SherlockMigrator

java.lang.Object
com.coditory.sherlock.SherlockMigrator

public final class SherlockMigrator extends Object
Migration mechanism based on Sherlock 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
  • Constructor Details

    • SherlockMigrator

      public SherlockMigrator(Sherlock sherlock)
      Parameters:
      sherlock - sherlock used to manage migration locks
    • SherlockMigrator

      public SherlockMigrator(String migrationId, Sherlock sherlock)
      Parameters:
      migrationId - id used as lock id for the whole migration process
      sherlock - sherlock used to manage migration locks
  • Method Details

    • addChangeSet

      public SherlockMigrator addChangeSet(String changeSetId, 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

      Runs the migration process.
      Returns:
      migration result