From 84e5ba08fe9bcb2edf59801bc2349dca83c4d990 Mon Sep 17 00:00:00 2001 From: Robert Oschwald Date: Sat, 19 Dec 2020 11:09:03 +0100 Subject: [PATCH] #152 call Callback methods only on pending migrations (as in 1.x) --- .../liquibase/GrailsLiquibase.groovy | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GrailsLiquibase.groovy b/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GrailsLiquibase.groovy index 05fdcd17..32bf7260 100644 --- a/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GrailsLiquibase.groovy +++ b/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GrailsLiquibase.groovy @@ -16,6 +16,8 @@ package org.grails.plugins.databasemigration.liquibase import groovy.transform.CompileStatic +import liquibase.Contexts +import liquibase.LabelExpression import liquibase.Liquibase import liquibase.database.Database import liquibase.exception.DatabaseException @@ -87,9 +89,18 @@ class GrailsLiquibase extends SpringLiquibase { def database = liquibase.database def migrationCallbacks = applicationContext.getBean('migrationCallbacks') + + if (!liquibase.listUnrunChangeSets(new Contexts(getContexts()), new LabelExpression(getLabels()))) { + log.info("No migrations to run for ${liquibase.database.connection.catalog}") + return + } + + log.info("Migrations detected for ${liquibase.database.connection.catalog}") + if (migrationCallbacks.metaClass.respondsTo(migrationCallbacks, 'beforeStartMigration')) { migrationCallbacks.invokeMethod('beforeStartMigration', [database] as Object[]) } + if (migrationCallbacks.metaClass.respondsTo(migrationCallbacks, 'onStartMigration')) { migrationCallbacks.invokeMethod('onStartMigration', [database, liquibase, changeLog] as Object[]) }