mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 00:59:34 +01:00
changed update script to fail on non-H2 databases; they require manual upgrades
This commit is contained in:
@@ -30,6 +30,8 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import org.owasp.dependencycheck.utils.DBUtils;
|
import org.owasp.dependencycheck.utils.DBUtils;
|
||||||
|
import org.owasp.dependencycheck.utils.DependencyVersion;
|
||||||
|
import org.owasp.dependencycheck.utils.DependencyVersionUtil;
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -288,6 +290,8 @@ public final class ConnectionFactory {
|
|||||||
* @throws DatabaseException thrown if there is an exception upgrading the database schema
|
* @throws DatabaseException thrown if there is an exception upgrading the database schema
|
||||||
*/
|
*/
|
||||||
private static void updateSchema(Connection conn, String schema) throws DatabaseException {
|
private static void updateSchema(Connection conn, String schema) throws DatabaseException {
|
||||||
|
final String databaseProductName = conn.getMetaData().getDatabaseProductName();
|
||||||
|
if ("h2".equalsIgnoreCase(databaseProductName)) {
|
||||||
LOGGER.debug("Updating database structure");
|
LOGGER.debug("Updating database structure");
|
||||||
InputStream is;
|
InputStream is;
|
||||||
InputStreamReader reader;
|
InputStreamReader reader;
|
||||||
@@ -328,7 +332,16 @@ public final class ConnectionFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.error("The database schema must be upgraded to use this version of dependency-check. Please see {} for more information.", UPGRADE_HELP_URL);
|
||||||
|
throw new DatabaseException("Database schema is out of date");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counter to ensure that calls to ensureSchemaVersion does not end up in an endless loop.
|
||||||
|
*/
|
||||||
|
private static int callDepth = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the provided connection to check the specified schema version within the database.
|
* Uses the provided connection to check the specified schema version within the database.
|
||||||
@@ -344,10 +357,15 @@ public final class ConnectionFactory {
|
|||||||
cs = conn.prepareCall("SELECT value FROM properties WHERE id = 'version'");
|
cs = conn.prepareCall("SELECT value FROM properties WHERE id = 'version'");
|
||||||
rs = cs.executeQuery();
|
rs = cs.executeQuery();
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
if (!DB_SCHEMA_VERSION.equals(rs.getString(1))) {
|
final DependencyVersion current = DependencyVersionUtil.parseVersion(DB_SCHEMA_VERSION);
|
||||||
|
final DependencyVersion db = DependencyVersionUtil.parseVersion(rs.getString(1));
|
||||||
|
if (current.compareTo(db) > 0) {
|
||||||
LOGGER.debug("Current Schema: " + DB_SCHEMA_VERSION);
|
LOGGER.debug("Current Schema: " + DB_SCHEMA_VERSION);
|
||||||
LOGGER.debug("DB Schema: " + rs.getString(1));
|
LOGGER.debug("DB Schema: " + rs.getString(1));
|
||||||
updateSchema(conn, rs.getString(1));
|
updateSchema(conn, rs.getString(1));
|
||||||
|
if (++callDepth < 10) {
|
||||||
|
ensureSchemaVersion(conn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new DatabaseException("Database schema is missing");
|
throw new DatabaseException("Database schema is missing");
|
||||||
|
|||||||
Reference in New Issue
Block a user