Skip to content
Snippets Groups Projects

More "semantic-versioning" compatible check for back-end schema

Merged Timm Fitschen requested to merge f-schema-version into dev
1 file
+ 55
11
Compare changes
  • Side-by-side
  • Inline
@@ -175,25 +175,69 @@ class DatabaseConnectionPool {
@@ -175,25 +175,69 @@ class DatabaseConnectionPool {
logger.debug("####################");
logger.debug("####################");
}
}
 
/**
 
* Check the version of the SQL server's database.
 
*
 
* <p>Current behaviour: Major versions must match and the database's minor version must be at
 
* least the expected minor version as defined in {@link
 
* ServerProperties.KEY_MYSQL_SCHEMA_VERSION}.
 
*
 
* <p>@todo Patch versions are not handled yet.
 
*/
private static void checkVersion(final Connection con)
private static void checkVersion(final Connection con)
throws SQLException, ConnectionException, CaosDBException {
throws SQLException, ConnectionException, CaosDBException {
try {
try {
 
final String[] expected_version =
 
CaosDBServer.getServerProperty(ServerProperties.KEY_MYSQL_SCHEMA_VERSION)
 
.toLowerCase()
 
.split("\\.");
 
final String expected_major = expected_version[0];
 
final String expected_minor = expected_version[1];
 
con.setReadOnly(false);
con.setReadOnly(false);
final PreparedStatement prepareStatement = con.prepareStatement("SELECT CaosDBVersion()");
final PreparedStatement prepared = con.prepareStatement("SELECT CaosDBVersion()");
try {
try {
final ResultSet executeQuery = prepareStatement.executeQuery();
final ResultSet executeQuery = prepared.executeQuery();
if (executeQuery.next()) {
if (executeQuery.next()) {
final String v_e =
CaosDBServer.getServerProperty(ServerProperties.KEY_MYSQL_SCHEMA_VERSION)
final String actual_version = executeQuery.getString(1).toLowerCase();
.toLowerCase();
final String[] actual_version_split = actual_version.split("\\.");
final String v_a = executeQuery.getString(1).toLowerCase();
final String actual_major = actual_version_split[0];
if (!Objects.equal(v_a, v_e)) {
final String actual_minor = actual_version_split[1];
logger.error(
"Version of the MySQL schema is wrong.\n\tExpected: {}\n\tActual: {}n\nPlease upgrade the mysql backend.\n\n",
if (!Objects.equal(actual_major, expected_major)) {
v_e,
if (Integer.parseInt(actual_major.replace("v", ""))
v_a);
< Integer.parseInt(expected_major.replace("v", ""))) {
 
logger.error(
 
"Version of the MySQL/MariaDB schema is incompatible.\n\tExpected: {}.{}\n\tActual: {}\nPlease upgrade the MySQL backend.\n\n",
 
expected_major,
 
expected_minor,
 
actual_version);
 
} else {
 
logger.error(
 
"Version of the MySQL/MariaDB schema is incompatible.\n\tExpected: {}.{}\n\tActual: {}\nPlease upgrade the CaosDB server.\n\n",
 
expected_major,
 
expected_minor,
 
actual_version);
 
}
System.exit(1);
System.exit(1);
}
}
 
if (!Objects.equal(actual_minor, expected_minor)) {
 
if (Integer.parseInt(actual_minor) < Integer.parseInt(expected_minor)) {
 
logger.error(
 
"Version of the MySQL/MariaDB schema is incompatible.\n\tExpected: {}.{}\n\tActual: {}\nPlease upgrade the MySQL backend.\n\n",
 
expected_major,
 
expected_minor,
 
actual_version);
 
System.exit(1);
 
}
 
}
 
} else {
 
logger.error(
 
"Version of the MySQL schema could not be determined. This probably means that the version is too old.\n\tExpected: {}.{}\n\tActual: unknown\nPlease upgrade the MySQL backend.\n\n",
 
expected_major,
 
expected_minor);
 
System.exit(1);
}
}
} catch (final SQLException e) {
} catch (final SQLException e) {
logger.error("Could not check the version of the MySQL schema.", e);
logger.error("Could not check the version of the MySQL schema.", e);
Loading