Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: ae2de0ba by Tony Chemit at 2023-06-01T08:38:15+02:00 Table de versionnage non présente dans certaines sauvegardes (depuis la version 9.0.X jusqu'à la 9.1.3) - Closes #2712 - - - - - 1 changed file: - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceContext.java Changes: ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceContext.java ===================================== @@ -38,6 +38,7 @@ import org.nuiton.topia.service.migration.version.TMSVersion; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.sql.SQLException; import java.util.Date; import java.util.List; import java.util.Objects; @@ -149,14 +150,15 @@ public class TopiaMigrationServiceContext { } } finally { if (v == null) { - //FIXME Is this can really happen? - // la base dans ce cas n'est pas versionee. - // On dit que la version de la base est 0 - // et les schema de cette version 0 doivent - // etre detenu en local - v = Version.VZERO; + // If no version found, db not versioned dbNotVersioned = true; - log.info("Database version not found, so database schema is considered as V0"); + try { + // We can still try to detect database version from the structure of the database + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2712 + v = detectVersionFromStructure(jdbcHelper); + log.warn("Database version table not found, but database version was guessed : {}", v); + } catch (SQLException ignored) { + } } else { log.info(String.format("Detected database version: %s", v)); } @@ -173,6 +175,25 @@ public class TopiaMigrationServiceContext { ); } + private static Version detectVersionFromStructure(JdbcHelper jdbcHelper) throws SQLException { + if (!jdbcHelper.isSchemaExist("ps_logbook")) { + // We are before v9.0 + return Version.valueOf("7.6"); + } + // try to detect v9.0 + if (jdbcHelper.isTableExist("ps_logbook", "wellPlan")) { + // We are on a version 9.0.x + return Version.valueOf("9.0"); + } + // try to detect v9.1 + if (jdbcHelper.isTableExist("ps_logbook", "well")) { + // We are on a version 9.1.x + return Version.valueOf("9.1"); + } + // We could not find the database version + throw new TopiaMigrationServiceException("Could not detected database version, no migration table found."); + } + public static TopiaMigrationServiceContext createLegacy(TopiaMigrationServiceConfiguration configuration) { TopiaApplicationContext<?> topiaApplicationContext = configuration.getApplicationContext(); boolean versionTableExist; @@ -303,9 +324,14 @@ public class TopiaMigrationServiceContext { log.info("Fill version table {} from legacy table.", dbVersion); saveVersion(sqlSupport, dbVersion, null); } else if (dbNotVersioned) { - log.info("Database is empty, no migration needed, set "); - saveVersion(sqlSupport, modelVersion, new Date()); - return false; + if (Version.VZERO.equals(dbVersion)) { + log.info("Database is empty, no migration needed, set current version {}", modelVersion); + saveVersion(sqlSupport, modelVersion, new Date()); + return false; + } else { + log.info("Fill version table {} from guessed version (even if no legacy nor default version table detected).", dbVersion); + saveVersion(sqlSupport, dbVersion, null); + } } // In all other cases, we can try to perform migration return true; View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/ae2de0ba743821f3886d03e68b... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/ae2de0ba743821f3886d03e68b... You're receiving this email because of your account on gitlab.com.