Skip to content

Instantly share code, notes, and snippets.

@yusufcakal
Created May 25, 2019 16:03
Show Gist options
  • Save yusufcakal/298716e7f24db26090caf46f64e721e2 to your computer and use it in GitHub Desktop.
Save yusufcakal/298716e7f24db26090caf46f64e721e2 to your computer and use it in GitHub Desktop.
Config class for liquibase
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
</databaseChangeLog>
import liquibase.integration.spring.SpringLiquibase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert;
import javax.sql.DataSource;
@Configuration
public class LiquibaseConfig {
private static final String DATABASE_CHANGELOG_FILE_PATH = "classpath:/database/changelog/database-changelog.xml";
@Autowired
private DataSource dataSource;
@Autowired
private ResourceLoader resourceLoader;
@Bean
public SpringLiquibase liquibase() {
String changelogFile = DATABASE_CHANGELOG_FILE_PATH;
Resource resource = resourceLoader.getResource(changelogFile);
Assert.state(resource.exists(), "Unable to find file: " + resource.getFilename());
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setChangeLog(changelogFile);
liquibase.setDataSource(dataSource);
return liquibase;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment