use of org.opennms.core.schema.Migrator in project opennms by OpenNMS.
the class MigratorIT method testMultipleChangelogs.
@Test
@JUnitTemporaryDatabase(createSchema = false)
public void testMultipleChangelogs() throws Exception {
assertFalse(changelogExists());
final Migration migration = new Migration();
migration.setAdminUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setAdminPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setDatabaseUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setDatabasePassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setChangeLog("changelog.xml");
final Migrator m = new Migrator();
m.setDataSource(m_dataSource);
m.setAdminDataSource(m_dataSource);
m.setValidateDatabaseVersion(false);
m.setCreateUser(false);
m.setCreateDatabase(false);
// from the classpath
for (final Resource resource : getTestResources()) {
URI uri = resource.getURI();
if (uri.getScheme().equals("jar") && !uri.toString().contains("test-api.schema"))
continue;
if (uri.getScheme().equals("file") && !uri.toString().contains("test-api/schema"))
continue;
LOG.info("=== found resource: {} ===", resource);
migration.setAccessor(new ExistingResourceAccessor(resource));
m.migrate(migration);
}
final List<ChangelogEntry> ids = getChangelogEntries();
assertTrue(ids.size() > 0);
assertEquals("test-api.schema.a", ids.get(0).getId());
assertEquals("test-api.schema.b", ids.get(1).getId());
}
use of org.opennms.core.schema.Migrator in project opennms by OpenNMS.
the class MigratorIT method doMigration.
private void doMigration() throws MigrationException, IOException {
final Migration migration = new Migration();
migration.setAdminUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setAdminPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setDatabaseUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setDatabasePassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setChangeLog("changelog.xml");
final Migrator m = new Migrator();
m.setDataSource(m_dataSource);
for (final Resource resource : getTestResources()) {
migration.setAccessor(new ExistingResourceAccessor(resource));
m.migrate(migration);
}
}
use of org.opennms.core.schema.Migrator in project opennms by OpenNMS.
the class MigratorIT method testRealChangelog.
@Test
@JUnitTemporaryDatabase(createSchema = false)
public void testRealChangelog() throws Exception {
assertFalse(changelogExists());
final Migration migration = new Migration();
migration.setAdminUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setAdminPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setDatabaseUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setDatabasePassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setChangeLog("changelog.xml");
final Migrator m = new Migrator();
m.setDataSource(m_dataSource);
m.setAdminDataSource(m_dataSource);
m.setValidateDatabaseVersion(false);
m.setCreateUser(false);
m.setCreateDatabase(false);
// from the classpath
for (final Resource resource : getRealChangelog()) {
LOG.info("=== found resource: {} ===", resource);
migration.setAccessor(new ExistingResourceAccessor(resource));
m.migrate(migration);
}
final List<ChangelogEntry> ids = getChangelogEntries();
assertTrue(ids.size() > 0);
// Check to make sure some of the changelogs ran
assertTrue(ids.stream().anyMatch(id -> "17.0.0-remove-legacy-ipinterface-composite-key-fields".equals(id.getId())));
assertTrue(ids.stream().anyMatch(id -> "17.0.0-remove-legacy-outages-composite-key-fields".equals(id.getId())));
}
use of org.opennms.core.schema.Migrator in project opennms by OpenNMS.
the class MigratorIT method testUpdate.
@Test
@JUnitTemporaryDatabase(createSchema = false)
public void testUpdate() throws Exception {
// Make sure there is no databasechangelog table
assertFalse(changelogExists());
Resource aResource = null;
for (final Resource resource : getTestResources()) {
URI uri = resource.getURI();
if (uri.getScheme().equals("file") && uri.toString().contains("test-api/schema/a")) {
aResource = resource;
}
if (uri.getScheme().equals("jar") && uri.toString().contains("test-api.schema.a")) {
aResource = resource;
}
}
assertNotNull("aResource must not be null", aResource);
Set<String> tables = getTables();
assertFalse("must not contain table 'schematest'", tables.contains("schematest"));
final Migration migration = new Migration();
migration.setAdminUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setAdminPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setDatabaseUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setDatabasePassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setChangeLog("changelog.xml");
migration.setAccessor(new ExistingResourceAccessor(aResource));
LOG.info("Running migration on database: {}", migration);
final Migrator m = new Migrator();
m.setDataSource(m_dataSource);
m.setAdminDataSource(m_dataSource);
m.setValidateDatabaseVersion(false);
m.setCreateUser(false);
m.setCreateDatabase(false);
m.prepareDatabase(migration);
m.migrate(migration);
LOG.info("Migration complete: {}", migration);
tables = getTables();
assertTrue("must contain table 'schematest'", tables.contains("schematest"));
}
Aggregations