Class SherlockMigrator


  • public final class SherlockMigrator
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      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.
      void migrate()
      Runs the migration process.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SherlockMigrator

        public SherlockMigrator​(java.lang.String migrationId,
                                Sherlock sherlock)
        Parameters:
        migrationId - id used as lock id for the whole migration process
        sherlock - 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 void migrate()
        Runs the migration process.