Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit e6cd291

Browse files
acanbyjdaugherty
authored andcommitted
Allow loading classpath resources for sqlFile changesets
1 parent b39e53a commit e6cd291

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

grails-database-migration/src/main/groovy/org/grails/plugins/databasemigration/DatabaseMigrationGrailsPlugin.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
4545
@Override
4646
Closure doWithSpring() {
4747
configureLiquibase()
48-
return { -> }
48+
return { ->
49+
grailsLiquibaseFactory(GrailsLiquibaseFactory, applicationContext)
50+
}
4951
}
5052

5153
@Override
@@ -71,7 +73,7 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
7173
}
7274

7375
new DatabaseMigrationTransactionManager(applicationContext, dataSourceName).withTransaction {
74-
GrailsLiquibase gl = new GrailsLiquibase(applicationContext)
76+
GrailsLiquibase gl = applicationContext.getBean('grailsLiquibaseFactory', GrailsLiquibase)
7577
gl.dataSource = getDataSourceBean(applicationContext, dataSourceName)
7678
gl.dropFirst = config.getProperty("${configPrefix}.dropOnStart", Boolean, false)
7779
gl.changeLog = config.getProperty("${configPrefix}.updateOnStartFileName", String, isDefaultDataSource(dataSourceName) ? 'changelog.groovy' : "changelog-${dataSourceName}.groovy")

grails-database-migration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GrailsLiquibase.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import liquibase.database.Database
2121
import liquibase.exception.DatabaseException
2222
import liquibase.exception.LiquibaseException
2323
import liquibase.integration.spring.SpringLiquibase
24-
import liquibase.resource.ClassLoaderResourceAccessor
2524
import liquibase.resource.ResourceAccessor
2625
import org.springframework.context.ApplicationContext
26+
import org.springframework.core.io.DefaultResourceLoader
2727

2828
import java.sql.Connection
2929

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

4343
GrailsLiquibase(ApplicationContext applicationContext) {
4444
this.applicationContext = applicationContext
45+
this.resourceLoader = new DefaultResourceLoader()
4546
}
4647

4748
@Override
4849
protected Liquibase createLiquibase(Connection connection) throws LiquibaseException {
49-
Liquibase liquibase = new Liquibase(getChangeLog(), new ClassLoaderResourceAccessor(), createDatabase (connection, null))
50+
Liquibase liquibase = new Liquibase(getChangeLog(), createResourceOpener(), createDatabase (connection, null))
5051
if (parameters != null) {
5152
for (Map.Entry<String, String> entry : parameters.entrySet()) {
5253
liquibase.setChangeLogParameter(entry.getKey(), entry.getValue())
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.grails.plugins.databasemigration.liquibase
2+
3+
import org.springframework.beans.factory.config.AbstractFactoryBean
4+
import org.springframework.context.ApplicationContext
5+
6+
class GrailsLiquibaseFactory extends AbstractFactoryBean<GrailsLiquibase> {
7+
8+
private final ApplicationContext applicationContext
9+
10+
GrailsLiquibaseFactory(ApplicationContext applicationContext) {
11+
setSingleton(false)
12+
this.applicationContext = applicationContext
13+
}
14+
15+
@Override
16+
Class<?> getObjectType() {
17+
return GrailsLiquibase
18+
}
19+
20+
@Override
21+
protected GrailsLiquibase createInstance() throws Exception {
22+
return new GrailsLiquibase(applicationContext)
23+
}
24+
}

0 commit comments

Comments
 (0)