Class AsyncSpringLiquibase

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ResourceLoaderAware

    public class AsyncSpringLiquibase
    extends org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase
    Specific liquibase.integration.spring.SpringLiquibase that will update the database asynchronously and close DataSource if necessary.

    By default, this asynchronous version only works when using the "dev" profile.

    The standard liquibase.integration.spring.SpringLiquibase starts Liquibase in the current thread:

    • This is needed if you want to do some database requests at startup
    • This ensure that the database is ready when the application starts
    But as this is a rather slow process, we use this asynchronous version to speed up our start-up time:
    • On a recent MacBook Pro, start-up time is down from 14 seconds to 8 seconds
    • In production, this can help your application run on platforms like Heroku, where it must start/restart very quickly
    • Nested Class Summary

      • Nested classes/interfaces inherited from class liquibase.integration.spring.SpringLiquibase

        liquibase.integration.spring.SpringLiquibase.SpringResourceOpener
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String DISABLED_MESSAGE
      Constant DISABLED_MESSAGE="Liquibase is disabled"
      static String EXCEPTION_MESSAGE
      Constant EXCEPTION_MESSAGE="Liquibase could not start correctly, yo"{trunked}
      static String SLOWNESS_MESSAGE
      Constant SLOWNESS_MESSAGE="Warning, Liquibase took more than {} se"{trunked}
      static long SLOWNESS_THRESHOLD
      Constant SLOWNESS_THRESHOLD=5
      static String STARTED_MESSAGE
      Constant STARTED_MESSAGE="Liquibase has updated your database in "{trunked}
      static String STARTING_ASYNC_MESSAGE
      Constant STARTING_ASYNC_MESSAGE="Starting Liquibase asynchronously, your"{trunked}
      static String STARTING_SYNC_MESSAGE
      Constant STARTING_SYNC_MESSAGE="Starting Liquibase synchronously"
      • Fields inherited from class liquibase.integration.spring.SpringLiquibase

        beanName, changeLog, clearCheckSums, contexts, databaseChangeLogLockTable, databaseChangeLogTable, dataSource, defaultSchema, dropFirst, labels, liquibaseSchema, liquibaseTablespace, log, parameters, resourceLoader, rollbackFile, shouldRun, tag, testRollbackOnUpdate
    • Constructor Summary

      Constructors 
      Constructor Description
      AsyncSpringLiquibase​(Executor executor, org.springframework.core.env.Environment env)
      Constructor for AsyncSpringLiquibase.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()
      protected void initDb()
      initDb.
      • Methods inherited from class org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase

        destroy, setCloseDataSourceOnceMigrated
      • Methods inherited from class liquibase.integration.spring.SpringLiquibase

        createDatabase, createLiquibase, createResourceOpener, getBeanName, getChangeLog, getContexts, getDatabaseChangeLogLockTable, getDatabaseChangeLogTable, getDatabaseProductName, getDataSource, getDefaultSchema, getLabels, getLiquibaseSchema, getLiquibaseTablespace, getResourceLoader, getTag, isClearCheckSums, isDropFirst, isIgnoreClasspathPrefix, isTestRollbackOnUpdate, performUpdate, setBeanName, setChangeLog, setChangeLogParameters, setClearCheckSums, setContexts, setDatabaseChangeLogLockTable, setDatabaseChangeLogTable, setDataSource, setDefaultSchema, setDropFirst, setIgnoreClasspathPrefix, setLabels, setLiquibaseSchema, setLiquibaseTablespace, setResourceLoader, setRollbackFile, setShouldRun, setTag, setTestRollbackOnUpdate, toString
    • Field Detail

      • DISABLED_MESSAGE

        public static final String DISABLED_MESSAGE
        Constant DISABLED_MESSAGE="Liquibase is disabled"
        See Also:
        Constant Field Values
      • STARTING_ASYNC_MESSAGE

        public static final String STARTING_ASYNC_MESSAGE
        Constant STARTING_ASYNC_MESSAGE="Starting Liquibase asynchronously, your"{trunked}
        See Also:
        Constant Field Values
      • STARTING_SYNC_MESSAGE

        public static final String STARTING_SYNC_MESSAGE
        Constant STARTING_SYNC_MESSAGE="Starting Liquibase synchronously"
        See Also:
        Constant Field Values
      • STARTED_MESSAGE

        public static final String STARTED_MESSAGE
        Constant STARTED_MESSAGE="Liquibase has updated your database in "{trunked}
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE

        public static final String EXCEPTION_MESSAGE
        Constant EXCEPTION_MESSAGE="Liquibase could not start correctly, yo"{trunked}
        See Also:
        Constant Field Values
      • SLOWNESS_THRESHOLD

        public static final long SLOWNESS_THRESHOLD
        Constant SLOWNESS_THRESHOLD=5
        See Also:
        Constant Field Values
      • SLOWNESS_MESSAGE

        public static final String SLOWNESS_MESSAGE
        Constant SLOWNESS_MESSAGE="Warning, Liquibase took more than {} se"{trunked}
        See Also:
        Constant Field Values
    • Constructor Detail

      • AsyncSpringLiquibase

        public AsyncSpringLiquibase​(Executor executor,
                                    org.springframework.core.env.Environment env)

        Constructor for AsyncSpringLiquibase.

        Parameters:
        executor - a Executor object.
        env - a Environment object.
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws liquibase.exception.LiquibaseException
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Overrides:
        afterPropertiesSet in class org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase
        Throws:
        liquibase.exception.LiquibaseException
      • initDb

        protected void initDb()
                       throws liquibase.exception.LiquibaseException

        initDb.

        Throws:
        liquibase.exception.LiquibaseException - if any.