Khushal/Gurpreet: Added support for Flyway DB migration tool into MifosX. Added a call for it in TomatJDBCDataSourcePerTenantService so that it gets called per tenant once.
This commit is contained in:
@@ -156,6 +156,7 @@ dependencies {
|
||||
[group: 'com.lowagie', name: 'itext', version: '2.1.7'],
|
||||
[group: 'com.lowagie', name: 'itext-rtf', version: '2.1.7'],
|
||||
[group: 'org.mnode.ical4j', name: 'ical4j', version: '1.0.4'],
|
||||
[group: 'com.googlecode.flyway', name: 'flyway-maven-plugin', version: '2.1.1']
|
||||
)
|
||||
|
||||
testCompile 'junit:junit:4.10',
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.mifosplatform.database;
|
||||
import com.googlecode.flyway.core.Flyway;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Use Flyway library to migrate DB schema. Searches for .sql files in the migrate folder.
|
||||
* For more details on this refer to:
|
||||
* http://flywaydb.org/documentation/migration/sql.html
|
||||
*/
|
||||
public class DBMigrationHelper {
|
||||
|
||||
// private static final String DB_CONNECTION_URL = "jdbc:mysql://localhost:3306/mifostenant-default";
|
||||
// private static final String DB_USER = "root";
|
||||
// private static final String DB_PASSWORD = "mysql";
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
public void migrateDB(DataSource tenantDataSource){
|
||||
|
||||
logger.info("Checking for DB Schema Migration. Tenant: "+ tenantDataSource);
|
||||
|
||||
Flyway flyway = new Flyway();
|
||||
flyway.setDataSource(tenantDataSource);
|
||||
flyway.migrate();
|
||||
}
|
||||
}
|
||||
+2
@@ -12,6 +12,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.mifosplatform.database.DBMigrationHelper;
|
||||
import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -51,6 +52,7 @@ public class TomcatJdbcDataSourcePerTenantService implements DataSourcePerTenant
|
||||
} else {
|
||||
tenantDataSource = createNewDataSourceFor(tenant);
|
||||
this.tenantToDataSourceMap.put(tenant.getId(), tenantDataSource);
|
||||
new DBMigrationHelper().migrateDB(tenantDataSource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user