[DEV] add variable to permit not check if the DB exist

This commit is contained in:
Edouard DUPIN 2025-02-09 22:05:35 +01:00
parent 20d2d004cb
commit 5f89ff7944
2 changed files with 41 additions and 26 deletions

View File

@ -11,6 +11,7 @@ import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.dataAccess.QueryOptions; import org.kar.archidata.dataAccess.QueryOptions;
import org.kar.archidata.db.DbConfig; import org.kar.archidata.db.DbConfig;
import org.kar.archidata.migration.model.Migration; import org.kar.archidata.migration.model.Migration;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -130,35 +131,40 @@ public class MigrationEngine {
} }
private void createTableIfAbleOrWaitAdmin(final DbConfig configInput) throws MigrationException { private void createTableIfAbleOrWaitAdmin(final DbConfig configInput) throws MigrationException {
final DbConfig config = configInput.clone(); if (ConfigBaseVariable.getDBAbleToCreate()) {
config.setDbName(null); final DbConfig config = configInput.clone();
final String dbName = configInput.getDbName(); config.setDbName(null);
LOGGER.info("Verify existance of '{}'", dbName); final String dbName = configInput.getDbName();
try (final DBAccess da = DBAccess.createInterface(config)) { LOGGER.info("Verify existance of '{}'", dbName);
boolean exist = da.isDBExist(dbName); try (final DBAccess da = DBAccess.createInterface(config)) {
if (!exist) { boolean exist = da.isDBExist(dbName);
LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", dbName); if (!exist) {
// create the local DB: LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", dbName);
da.createDB(dbName); // create the local DB:
} da.createDB(dbName);
exist = da.isDBExist(dbName);
while (!exist) {
LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", dbName);
LOGGER.error("Waiting administrator create a new one, we check after 30 seconds...");
try {
Thread.sleep(30000);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
exist = da.isDBExist(dbName); exist = da.isDBExist(dbName);
while (!exist) {
LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", dbName);
LOGGER.error("Waiting administrator create a new one, we check after 30 seconds...");
try {
Thread.sleep(30000);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
exist = da.isDBExist(dbName);
}
} catch (final InternalServerErrorException e) {
e.printStackTrace();
throw new MigrationException("TODO ...");
} catch (final IOException e) {
e.printStackTrace();
throw new MigrationException("TODO ...");
} }
} catch (final InternalServerErrorException e) { } else {
e.printStackTrace(); final String dbName = configInput.getDbName();
throw new MigrationException("TODO ..."); LOGGER.warn("DB: '{}' is not check if it EXIST", dbName);
} catch (final IOException e) {
e.printStackTrace();
throw new MigrationException("TODO ...");
} }
} }

View File

@ -3,6 +3,7 @@ package org.kar.archidata.tools;
public class ConfigBaseVariable { public class ConfigBaseVariable {
static public String tmpDataFolder; static public String tmpDataFolder;
static public String dataFolder; static public String dataFolder;
static public String dbAbleToCreate;
static public String dbType; static public String dbType;
static public String dbHost; static public String dbHost;
static public String dbPort; static public String dbPort;
@ -23,6 +24,7 @@ public class ConfigBaseVariable {
public static void clearAllValue() { public static void clearAllValue() {
tmpDataFolder = System.getenv("DATA_TMP_FOLDER"); tmpDataFolder = System.getenv("DATA_TMP_FOLDER");
dataFolder = System.getenv("DATA_FOLDER"); dataFolder = System.getenv("DATA_FOLDER");
dbAbleToCreate = System.getenv("DB_ABLE_TO_CREATE");
dbType = System.getenv("DB_TYPE"); dbType = System.getenv("DB_TYPE");
dbHost = System.getenv("DB_HOST"); dbHost = System.getenv("DB_HOST");
dbPort = System.getenv("DB_PORT"); dbPort = System.getenv("DB_PORT");
@ -58,6 +60,13 @@ public class ConfigBaseVariable {
return dataFolder; return dataFolder;
} }
public static boolean getDBAbleToCreate() {
if (dbAbleToCreate == null) {
return true;
}
return Boolean.getBoolean(dbAbleToCreate);
}
public static String getDBType() { public static String getDBType() {
if (dbType == null) { if (dbType == null) {
return "mysql"; return "mysql";