use of liquibase.Liquibase in project openmrs-core by openmrs.
the class DatabaseUpdater method releaseDatabaseLock.
/**
* This method releases the liquibase db lock after a crashed database update. First, it
* checks whether "liquibasechangeloglock" table exists in db. If so, it will check
* whether the database is locked. If that is also true, this means that last attempted db
* update crashed.<br>
* <br>
* This should only be called if the user is sure that no one else is currently running
* database updates. This method should be used if there was a db crash while updates
* were being written and the lock table was never cleaned up.
*
* @throws LockException
*/
public static synchronized void releaseDatabaseLock() throws LockException {
Database database = null;
try {
Liquibase liquibase = getLiquibase(null, null);
database = liquibase.getDatabase();
if (database.hasDatabaseChangeLogLockTable() && isLocked()) {
LockService.getInstance(database).forceReleaseLock();
}
} catch (Exception e) {
throw new LockException(e);
} finally {
try {
database.getConnection().close();
} catch (Exception e) {
// pass
}
}
}
use of liquibase.Liquibase in project traccar by traccar.
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 microservice_framework by CJSCommonPlatform.
the class AbstractJdbcRepositoryIT method initDatabase.
private void initDatabase() throws Exception {
Liquibase liquibase = new Liquibase(liquibaseLocation, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
liquibase.dropAll();
liquibase.update("");
}
use of liquibase.Liquibase in project microservice_framework by CJSCommonPlatform.
the class EventsPageIT method initEventDatabase.
private void initEventDatabase() throws Exception {
Liquibase eventStoreLiquibase = new Liquibase(LIQUIBASE_EVENT_STORE_CHANGELOG_XML, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
eventStoreLiquibase.dropAll();
eventStoreLiquibase.update("");
}
use of liquibase.Liquibase in project microservice_framework by CJSCommonPlatform.
the class CakeShopPostgresIT method initDatabase.
private static DataSource initDatabase(final String dbUrlPropertyName, final String dbUserNamePropertyName, final String dbPasswordPropertyName, final String... liquibaseChangeLogXmls) throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(POSTGRES_DRIVER);
dataSource.setUrl(TEST_PROPERTIES.value(dbUrlPropertyName));
dataSource.setUsername(TEST_PROPERTIES.value(dbUserNamePropertyName));
dataSource.setPassword(TEST_PROPERTIES.value(dbPasswordPropertyName));
boolean dropped = false;
final JdbcConnection jdbcConnection = new JdbcConnection(dataSource.getConnection());
for (String liquibaseChangeLogXml : liquibaseChangeLogXmls) {
Liquibase liquibase = new Liquibase(liquibaseChangeLogXml, new ClassLoaderResourceAccessor(), jdbcConnection);
if (!dropped) {
liquibase.dropAll();
dropped = true;
}
liquibase.update("");
}
return dataSource;
}
Aggregations