use of liquibase.Liquibase in project opennms by OpenNMS.
the class Migrator method migrate.
/**
* <p>migrate</p>
*
* @param migration a {@link org.opennms.core.schema.Migration} object.
* @throws org.opennms.core.schema.MigrationException if any.
*/
public void migrate(final Migration migration) throws MigrationException {
Connection connection = null;
DatabaseConnection dbConnection = null;
try {
connection = m_dataSource.getConnection();
dbConnection = new JdbcConnection(connection);
ResourceAccessor accessor = migration.getAccessor();
if (accessor == null)
accessor = new SpringResourceAccessor();
final Liquibase liquibase = new Liquibase(migration.getChangeLog(), accessor, dbConnection);
liquibase.setChangeLogParameter("install.database.admin.user", migration.getAdminUser());
liquibase.setChangeLogParameter("install.database.admin.password", migration.getAdminPassword());
liquibase.setChangeLogParameter("install.database.user", migration.getDatabaseUser());
liquibase.getDatabase().setDefaultSchemaName(migration.getSchemaName());
final String contexts = System.getProperty("opennms.contexts", "production");
liquibase.update(contexts);
} catch (final Throwable e) {
throw new MigrationException("unable to migrate the database", e);
} finally {
cleanUpDatabase(connection, dbConnection, null, null);
}
}
use of liquibase.Liquibase in project traccar by tananaev.
the class DataManager method initDatabaseSchema.
private void initDatabaseSchema() throws SQLException, LiquibaseException {
if (config.hasKey("database.changelog")) {
ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
Database database = DatabaseFactory.getInstance().openDatabase(config.getString("database.url"), config.getString("database.user"), config.getString("database.password"), null, resourceAccessor);
Liquibase liquibase = new Liquibase(config.getString("database.changelog"), resourceAccessor, database);
liquibase.clearCheckSums();
liquibase.update(new Contexts());
}
}
use of liquibase.Liquibase in project Singularity by HubSpot.
the class SingularityHistoryTest method createTestData.
@Before
public void createTestData() throws Exception {
Handle handle = dbiProvider.get().open();
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection()));
Liquibase liquibase = new Liquibase("singularity_test.sql", new FileSystemResourceAccessor(), database);
liquibase.update((String) null);
try {
database.close();
} catch (Throwable t) {
}
handle.close();
}
use of liquibase.Liquibase in project openmrs-core by openmrs.
the class DatabaseUpgradeTestUtil method upgrade.
public void upgrade(String filename) throws IOException, SQLException {
try {
Liquibase liquibase = new Liquibase(filename, new ClassLoaderResourceAccessor(getClass().getClassLoader()), liqubaseConnection);
liquibase.update(null);
connection.commit();
} catch (LiquibaseException e) {
throw new IOException(e);
}
}
use of liquibase.Liquibase in project openmrs-core by openmrs.
the class DatabaseUpdater method getLiquibase.
/**
* Get a connection to the database through Liquibase. The calling method /must/ close the
* database connection when finished with this Liquibase object.
* liquibase.getDatabase().getConnection().close()
*
* @param changeLogFile the name of the file to look for the on classpath or filesystem
* @param cl the {@link ClassLoader} to use to find the file (or null to use
* {@link OpenmrsClassLoader})
* @return Liquibase object based on the current connection settings
* @throws Exception
*/
private static Liquibase getLiquibase(String changeLogFile, ClassLoader cl) throws Exception {
Connection connection;
try {
connection = getConnection();
} catch (SQLException e) {
throw new Exception("Unable to get a connection to the database. Please check your openmrs runtime properties file and make sure you have the correct connection.username and connection.password set", e);
}
if (cl == null) {
cl = OpenmrsClassLoader.getInstance();
}
try {
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
database.setDatabaseChangeLogTableName("liquibasechangelog");
database.setDatabaseChangeLogLockTableName("liquibasechangeloglock");
if (connection.getMetaData().getDatabaseProductName().contains("HSQL Database Engine") || connection.getMetaData().getDatabaseProductName().contains("H2")) {
// a hack because hsqldb and h2 seem to be checking table names in the metadata section case sensitively
database.setDatabaseChangeLogTableName(database.getDatabaseChangeLogTableName().toUpperCase());
database.setDatabaseChangeLogLockTableName(database.getDatabaseChangeLogLockTableName().toUpperCase());
}
ResourceAccessor openmrsFO = new ClassLoaderFileOpener(cl);
ResourceAccessor fsFO = new FileSystemResourceAccessor();
if (changeLogFile == null) {
changeLogFile = CHANGE_LOG_FILE;
}
database.checkDatabaseChangeLogTable(false, null, null);
return new Liquibase(changeLogFile, new CompositeResourceAccessor(openmrsFO, fsFO), database);
} catch (Exception e) {
// if an error occurs, close the connection
if (connection != null) {
connection.close();
}
throw e;
}
}
Aggregations