Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import grails.plugins.Plugin
import liquibase.parser.ChangeLogParser
import liquibase.parser.ChangeLogParserFactory
import org.grails.plugins.databasemigration.liquibase.GrailsLiquibase
import org.grails.plugins.databasemigration.liquibase.GrailsLiquibaseFactory
import org.grails.plugins.databasemigration.liquibase.GroovyChangeLogParser
import org.springframework.context.ApplicationContext

Expand All @@ -45,7 +46,9 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
@Override
Closure doWithSpring() {
configureLiquibase()
return { -> }
return { ->
grailsLiquibaseFactory(GrailsLiquibaseFactory, applicationContext)
}
}

@Override
Expand All @@ -71,7 +74,7 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
}

new DatabaseMigrationTransactionManager(applicationContext, dataSourceName).withTransaction {
GrailsLiquibase gl = new GrailsLiquibase(applicationContext)
GrailsLiquibase gl = applicationContext.getBean('grailsLiquibaseFactory', GrailsLiquibase)
gl.dataSource = getDataSourceBean(applicationContext, dataSourceName)
gl.dropFirst = config.getProperty("${configPrefix}.dropOnStart", Boolean, false)
gl.changeLog = config.getProperty("${configPrefix}.updateOnStartFileName", String, isDefaultDataSource(dataSourceName) ? 'changelog.groovy' : "changelog-${dataSourceName}.groovy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import liquibase.database.Database
import liquibase.exception.DatabaseException
import liquibase.exception.LiquibaseException
import liquibase.integration.spring.SpringLiquibase
import liquibase.resource.ClassLoaderResourceAccessor
import liquibase.resource.ResourceAccessor
import org.springframework.context.ApplicationContext
import org.springframework.core.io.DefaultResourceLoader

import java.sql.Connection

Expand All @@ -42,11 +42,12 @@ class GrailsLiquibase extends SpringLiquibase {

GrailsLiquibase(ApplicationContext applicationContext) {
this.applicationContext = applicationContext
this.resourceLoader = new DefaultResourceLoader()
}

@Override
protected Liquibase createLiquibase(Connection connection) throws LiquibaseException {
Liquibase liquibase = new Liquibase(getChangeLog(), new ClassLoaderResourceAccessor(), createDatabase (connection, null))
Liquibase liquibase = new Liquibase(getChangeLog(), createResourceOpener(), createDatabase (connection, null))
if (parameters != null) {
for (Map.Entry<String, String> entry : parameters.entrySet()) {
liquibase.setChangeLogParameter(entry.getKey(), entry.getValue())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.grails.plugins.databasemigration.liquibase

import org.springframework.beans.factory.config.AbstractFactoryBean
import org.springframework.context.ApplicationContext

class GrailsLiquibaseFactory extends AbstractFactoryBean<GrailsLiquibase> {

private final ApplicationContext applicationContext

GrailsLiquibaseFactory(ApplicationContext applicationContext) {
setSingleton(false)
this.applicationContext = applicationContext
}

@Override
Class<?> getObjectType() {
return GrailsLiquibase
}

@Override
protected GrailsLiquibase createInstance() throws Exception {
return new GrailsLiquibase(applicationContext)
}
}
Loading