diff --git a/conf/core/server.conf b/conf/core/server.conf index ccf332edb423ee1d3fde59597db93ed0c2316cdd..153f76914618d8c524ea417586cb48481e16bf88 100644 --- a/conf/core/server.conf +++ b/conf/core/server.conf @@ -67,8 +67,8 @@ MYSQL_DATABASE_NAME=caosdb MYSQL_USER_NAME=caosdb # Password for the user MYSQL_USER_PASSWORD=caosdb -# Schema of mysql procedures and tables which is required by this CaosDB instance. The versioning follows SemVer 2.0 specs. -MYSQL_SCHEMA_VERSION=v4.0.0 +# Schema of mysql procedures and tables which is required by this CaosDB instance +MYSQL_SCHEMA_VERSION=v5.0 # -------------------------------------------------- diff --git a/src/doc/Glossary.md b/src/doc/Glossary.md index 080c2aea4ff393d349553f7d7211d35518ff7c11..39baab24d17fae531dd18d0f4a1fcc2329ec1035 100644 --- a/src/doc/Glossary.md +++ b/src/doc/Glossary.md @@ -1,5 +1,9 @@ # Glossary +## Valid ID + +The ID of an existing entity. It is by definition unique among the IDs of all existing entities and is a positive integer." + ## Valid Unique Existing Name A name of an exiting entity which is unique among the names of all existing entities. @@ -8,10 +12,6 @@ A name of an exiting entity which is unique among the names of all existing enti A name of a to-be-inserted/updated entity _e_ which is unique among the names of all other entities that are to be inserted or updated along with the entity _e_. -## Valid ID - -The ID of an existing entity. It is by definition unique among the IDs of all existing entities and is a positive integer." - ## Valid Unique Temporary ID The negative integer ID of a to-be-inserted entity _e_ which is unique among the ids of all other entities that are to be inserted along with the entity _e_. diff --git a/src/doc/concepts.rst b/src/doc/concepts.rst index 0db6186302302767c49735bcdfa81364685573f9..4403c95810f9b2edaa67e8561306b80031ac803e 100644 --- a/src/doc/concepts.rst +++ b/src/doc/concepts.rst @@ -7,7 +7,7 @@ Basic concepts of the CaosDB server :glob: Data Model <Data-Model> - Permissions + permissions roles The CaosDB server provides the HTTP API resources to users and client libraries. It uses a plain diff --git a/src/doc/Permissions.rst b/src/doc/permissions.rst similarity index 100% rename from src/doc/Permissions.rst rename to src/doc/permissions.rst diff --git a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseConnectionPool.java b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseConnectionPool.java index f77f810a93428a66247b6559e2bef2ac344cd5d9..997de3141db6fd49ac510fa61150a2d16e7d5416 100644 --- a/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseConnectionPool.java +++ b/src/main/java/org/caosdb/server/database/backend/implementation/MySQL/DatabaseConnectionPool.java @@ -175,25 +175,69 @@ class DatabaseConnectionPool { 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) throws SQLException, ConnectionException, CaosDBException { 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); - final PreparedStatement prepareStatement = con.prepareStatement("SELECT CaosDBVersion()"); + final PreparedStatement prepared = con.prepareStatement("SELECT CaosDBVersion()"); try { - final ResultSet executeQuery = prepareStatement.executeQuery(); + final ResultSet executeQuery = prepared.executeQuery(); if (executeQuery.next()) { - final String v_e = - CaosDBServer.getServerProperty(ServerProperties.KEY_MYSQL_SCHEMA_VERSION) - .toLowerCase(); - final String v_a = executeQuery.getString(1).toLowerCase(); - if (!Objects.equal(v_a, v_e)) { - logger.error( - "Version of the MySQL schema is wrong.\n\tExpected: {}\n\tActual: {}n\nPlease upgrade the mysql backend.\n\n", - v_e, - v_a); + + final String actual_version = executeQuery.getString(1).toLowerCase(); + final String[] actual_version_split = actual_version.split("\\."); + final String actual_major = actual_version_split[0]; + final String actual_minor = actual_version_split[1]; + + if (!Objects.equal(actual_major, expected_major)) { + if (Integer.parseInt(actual_major.replace("v", "")) + < 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); } + 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) { logger.error("Could not check the version of the MySQL schema.", e);