[DEV] migration manage first migration
This commit is contained in:
parent
1826f40874
commit
6cf67a1143
@ -1026,15 +1026,15 @@ public class SqlWrapper {
|
||||
query.append(tableName);
|
||||
query.append(".deleted = false ");
|
||||
firstField = true;
|
||||
LOGGER.info("generate the querry: '{}'", query.toString());
|
||||
LOGGER.info("request get {} prepare @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
LOGGER.debug("generate the querry: '{}'", query.toString());
|
||||
LOGGER.debug("request get {} prepare @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
// prepare the request:
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
LOGGER.info("request get {} query @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
LOGGER.debug("request get {} query @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
// execute the request
|
||||
ResultSet rs = ps.executeQuery();
|
||||
LOGGER.info("request get {} transform @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
LOGGER.debug("request get {} transform @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
|
||||
while (rs.next()) {
|
||||
indexAutoClasify = 0;
|
||||
@ -1065,7 +1065,7 @@ public class SqlWrapper {
|
||||
out.add((T)data);
|
||||
}
|
||||
|
||||
LOGGER.info("request get {} ready @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
LOGGER.debug("request get {} ready @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -101,9 +101,8 @@ public class MigrationEngine {
|
||||
}
|
||||
LOGGER.info("Create Table with : {}", sqlQuery.get(0));
|
||||
try {
|
||||
SqlWrapper.executeQuerry(sqlQuery.get(0));//.replace("`", "").replace("\t", ""));
|
||||
SqlWrapper.executeQuerry(sqlQuery.get(0));
|
||||
} catch (SQLException | IOException ex) {
|
||||
// TODO Auto-generated catch block
|
||||
ex.printStackTrace();
|
||||
while (true) {
|
||||
LOGGER.error("Fail to create the local DB model for migaration ==> wait administrator interventions");
|
||||
@ -121,6 +120,24 @@ public class MigrationEngine {
|
||||
} else {
|
||||
toApply.add(this.init);
|
||||
}
|
||||
if (this.datas.size() == 0) {
|
||||
// nothing to do the initialization model is alone and it is the first time
|
||||
} else {
|
||||
// we insert a placeholder to simulate all migration is well done.
|
||||
String placeholderName = this.datas.get(this.datas.size()-1).getName();
|
||||
MigrationModel migrationResult = new MigrationModel();
|
||||
migrationResult.name = placeholderName;
|
||||
migrationResult.stepId = 0;
|
||||
migrationResult.terminated = true;
|
||||
migrationResult.count = 0;
|
||||
migrationResult.log = "Place-holder for first initialization";
|
||||
try {
|
||||
migrationResult = SqlWrapper.insert(migrationResult);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (currentVersion.terminated == false) {
|
||||
while(true) {
|
||||
@ -129,7 +146,7 @@ public class MigrationEngine {
|
||||
}
|
||||
}
|
||||
LOGGER.info("Upgrade the system Current version: {}", currentVersion);
|
||||
boolean find = false;
|
||||
boolean find = this.init != null && this.init.getName() == currentVersion.name;
|
||||
for (int iii=0; iii<this.datas.size(); iii++) {
|
||||
if ( ! find) {
|
||||
if (this.datas.get(iii).getName() == currentVersion.name) {
|
||||
@ -170,10 +187,26 @@ public class MigrationEngine {
|
||||
try {
|
||||
SqlWrapper.update(migrationResult, migrationResult.id, List.of("terminated"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
log.append("Fail in the migration engine...");
|
||||
migrationResult.log = log.toString();
|
||||
SqlWrapper.update(migrationResult, migrationResult.id, List.of("log"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
while(true) {
|
||||
LOGGER.error("An error occured in the migration (OUTSIDE detection): '{}' defect @{}/{} ==> wait administrator interventions", migrationResult.name , migrationResult.stepId, migrationResult.count);
|
||||
try {
|
||||
Thread.sleep(60*60*1000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGGER.info("Migrate: [{}/{}] {} [ END ]", id, count, elem.getName());
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,6 @@ public class MigrationSqlStep implements MigrationInterface{
|
||||
try {
|
||||
SqlWrapper.update(model, model.id, List.of("stepId", "log"));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@ -54,7 +53,7 @@ public class MigrationSqlStep implements MigrationInterface{
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
Loading…
x
Reference in New Issue
Block a user