Class BaseJavaMigration

  • All Implemented Interfaces:
    JavaMigration

    public abstract class BaseJavaMigration
    extends java.lang.Object
    implements JavaMigration

    This is the recommended class to extend for implementing Java-based Migrations.

    Subclasses should follow the default Flyway naming convention of having a class name with the following structure:

    • Versioned Migrations: V2__Add_new_table
    • Undo Migrations: U2__Add_new_table
    • Repeatable Migrations: R__Add_new_table

    The file name consists of the following parts:

    • Prefix: V for versioned migrations, U for undo migrations, R for repeatable 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 Flyway's default naming convention.
    • Method Summary

      Modifier and Type Method Description
      boolean canExecuteInTransaction()
      Whether the execution should take place inside a transaction.
      java.lang.Integer getChecksum()
      Computes the checksum of the migration.
      java.lang.String getDescription()  
      MigrationVersion getVersion()  
      boolean isUndo()
      Whether this is an undo migration for a previously applied versioned migration.
      • Methods inherited from class java.lang.Object

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

      • BaseJavaMigration

        public BaseJavaMigration()
        Creates a new instance of a Java-based migration following Flyway's default naming convention.
    • Method Detail

      • getVersion

        public MigrationVersion getVersion()
        Specified by:
        getVersion in interface JavaMigration
        Returns:
        The version of the schema after the migration is complete. null for repeatable migrations.
      • getDescription

        public java.lang.String getDescription()
        Specified by:
        getDescription in interface JavaMigration
        Returns:
        The description of this migration for the migration history. Never null.
      • getChecksum

        public java.lang.Integer getChecksum()
        Description copied from interface: JavaMigration
        Computes the checksum of the migration.
        Specified by:
        getChecksum in interface JavaMigration
        Returns:
        The checksum of the migration.
      • isUndo

        public boolean isUndo()
        Description copied from interface: JavaMigration
        Whether this is an undo migration for a previously applied versioned migration.
        Specified by:
        isUndo in interface JavaMigration
        Returns:
        true if it is, false if not. Always false for repeatable migrations.
      • canExecuteInTransaction

        public boolean canExecuteInTransaction()
        Description copied from interface: JavaMigration
        Whether the execution should take place inside a transaction. Almost all implementation should return true. 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:
        canExecuteInTransaction in interface JavaMigration
        Returns:
        true if a transaction should be used (highly recommended), or false if not.