Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: c54977df by Tony Chemit at 2023-05-31T20:29:11+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,19 +150,40 @@ 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"); + // This case should never happen :( but v9.0.x is sometime without versioning table + // We can still try to find db version from database structure + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2712 + try { + // try to detect v9.0 + if (jdbcHelper.isTableExist("ps_logbook", "wellPlan")) { + // We are on a version 9.0.x + v = Version.valueOf("9.0"); + } + } catch (SQLException ignored) { + } + if (v == null) { + // try to detect v9.1 + try { + if (jdbcHelper.isTableExist("ps_logbook", "well")) { + // We are on a version 9.0.x + v = Version.valueOf("9.1"); + } + } catch (SQLException ignored) { + } + } + if (v != null) { + log.warn("Database version table not found, but database version was guessed : {}", v); + } } else { log.info(String.format("Detected database version: %s", v)); } dbVersion = v; } + if (dbVersion == null) { + throw new TopiaMigrationServiceException("Could not detected database version, no migration table found."); + } return new TopiaMigrationServiceContext(configuration, sqlHelper, legacyVersionTableExist, @@ -303,9 +325,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/c54977dfe4c1f12226c1336a3a... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/c54977dfe4c1f12226c1336a3a... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT (@tchemit)