Skip to content
Snippets Groups Projects

Update MySQL Schema

Merged Timm Fitschen requested to merge f-cleanup-rules into f-schema-version
1 file
+ 44
9
Compare changes
  • Side-by-side
  • Inline
@@ -178,22 +178,57 @@ class DatabaseConnectionPool {
@@ -178,22 +178,57 @@ class DatabaseConnectionPool {
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 prepareStatement = con.prepareStatement("SELECT CaosDBVersion()");
try {
try {
final ResultSet executeQuery = prepareStatement.executeQuery();
final ResultSet executeQuery = prepareStatement.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 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