Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,37 +226,46 @@ public void upgradeDatabase(boolean runScripts) throws StartupException {

log.info("Database is old, beginning upgrade to version "+myVersion);

boolean schemaChangesRequired = dbversion < 610;
// track whether any upgrade step actually ran, so the
// "no table changes" message stays correct without a
// hardcoded version constant
boolean schemaUpgraded = false;

// iterate through each upgrade as needed
// to add to the upgrade sequence simply add a new "if" statement
// for whatever version needed and then define a new method upgradeXXX()
// for whatever version needed, define a new method upgradeXXX(),
// and set schemaUpgraded = true

if(dbversion < 400) {
upgradeTo400(con, runScripts);
dbversion = 400;
schemaUpgraded = true;
}
if(dbversion < 500) {
upgradeTo500(con, runScripts);
dbversion = 500;
schemaUpgraded = true;
}
if(dbversion < 510) {
upgradeTo510(con, runScripts);
dbversion = 510;
schemaUpgraded = true;
}
if(dbversion < 520) {
upgradeTo520(con, runScripts);
dbversion = 520;
schemaUpgraded = true;
}
if(dbversion < 610) {
upgradeTo610(con, runScripts);
dbversion = 610;
schemaUpgraded = true;
}

// make sure the database version is the exact version
// we are upgrading too.
updateDatabaseVersion(con, myVersion);
if (!schemaChangesRequired) {
if (!schemaUpgraded) {
successMessage("No table changes were required.");
}
successMessage("Database version updated to " + myVersion + ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,36 @@ void versionOnlyUpgradeReportsCompletion() throws Exception {
assertTrue(installer.getMessages().stream().anyMatch(m -> m.contains("No table changes were required.")));
assertTrue(installer.getMessages().stream().anyMatch(m -> m.contains("Database version updated to " + expectedVersion + ".")));
}

@Test
void schemaUpgradeSuppressesNoChangesMessage() throws Exception {
DatabaseProvider db = mock(DatabaseProvider.class);
DatabaseScriptProvider scripts = mock(DatabaseScriptProvider.class);
Connection con = mock(Connection.class);
Statement query = mock(Statement.class);
ResultSet rows = mock(ResultSet.class);
PreparedStatement update = mock(PreparedStatement.class);
when(db.getConnection()).thenReturn(con);
when(con.createStatement()).thenReturn(query);
when(query.executeQuery(anyString())).thenReturn(rows);
when(rows.next()).thenReturn(true);
when(rows.getString(1)).thenReturn("520");
when(con.prepareStatement(anyString())).thenReturn(update);
DatabaseInstaller installer = new DatabaseInstaller(db, scripts);

Properties props = new Properties();
props.load(getClass().getResourceAsStream("/roller-version.properties"));
int expectedVersion = DatabaseInstaller.parseVersionString(props.getProperty("ro.version", "UNKNOWN"));

// a 520 database upgrades through the 520->610 schema step; run with
// runScripts=false so the step does its bookkeeping without executing a
// migration script. Because a schema step ran, the "no table changes"
// message must be suppressed.
installer.upgradeDatabase(false);

verify(update).setString(1, String.valueOf(expectedVersion));
verify(update).executeUpdate();
assertTrue(installer.getMessages().stream().anyMatch(m -> m.contains("Database version updated to " + expectedVersion + ".")));
assertFalse(installer.getMessages().stream().anyMatch(m -> m.contains("No table changes were required.")));
}
}
Loading