[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(tableName);
|
||||||
query.append(".deleted = false ");
|
query.append(".deleted = false ");
|
||||||
firstField = true;
|
firstField = true;
|
||||||
LOGGER.info("generate the querry: '{}'", query.toString());
|
LOGGER.debug("generate the querry: '{}'", query.toString());
|
||||||
LOGGER.info("request get {} prepare @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
LOGGER.debug("request get {} prepare @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||||
// prepare the request:
|
// prepare the request:
|
||||||
PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
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
|
// execute the request
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
LOGGER.info("request get {} transform @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
LOGGER.debug("request get {} transform @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
indexAutoClasify = 0;
|
indexAutoClasify = 0;
|
||||||
@ -1065,7 +1065,7 @@ public class SqlWrapper {
|
|||||||
out.add((T)data);
|
out.add((T)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("request get {} ready @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
LOGGER.debug("request get {} ready @{}", clazz.getCanonicalName(), getCurrentTimeStamp());
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
@ -101,9 +101,8 @@ public class MigrationEngine {
|
|||||||
}
|
}
|
||||||
LOGGER.info("Create Table with : {}", sqlQuery.get(0));
|
LOGGER.info("Create Table with : {}", sqlQuery.get(0));
|
||||||
try {
|
try {
|
||||||
SqlWrapper.executeQuerry(sqlQuery.get(0));//.replace("`", "").replace("\t", ""));
|
SqlWrapper.executeQuerry(sqlQuery.get(0));
|
||||||
} catch (SQLException | IOException ex) {
|
} catch (SQLException | IOException ex) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
while (true) {
|
while (true) {
|
||||||
LOGGER.error("Fail to create the local DB model for migaration ==> wait administrator interventions");
|
LOGGER.error("Fail to create the local DB model for migaration ==> wait administrator interventions");
|
||||||
@ -121,6 +120,24 @@ public class MigrationEngine {
|
|||||||
} else {
|
} else {
|
||||||
toApply.add(this.init);
|
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 {
|
} else {
|
||||||
if (currentVersion.terminated == false) {
|
if (currentVersion.terminated == false) {
|
||||||
while(true) {
|
while(true) {
|
||||||
@ -129,7 +146,7 @@ public class MigrationEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.info("Upgrade the system Current version: {}", currentVersion);
|
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++) {
|
for (int iii=0; iii<this.datas.size(); iii++) {
|
||||||
if ( ! find) {
|
if ( ! find) {
|
||||||
if (this.datas.get(iii).getName() == currentVersion.name) {
|
if (this.datas.get(iii).getName() == currentVersion.name) {
|
||||||
@ -170,9 +187,25 @@ public class MigrationEngine {
|
|||||||
try {
|
try {
|
||||||
SqlWrapper.update(migrationResult, migrationResult.id, List.of("terminated"));
|
SqlWrapper.update(migrationResult, migrationResult.id, List.of("terminated"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
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());
|
LOGGER.info("Migrate: [{}/{}] {} [ END ]", id, count, elem.getName());
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ public class MigrationSqlStep implements MigrationInterface{
|
|||||||
try {
|
try {
|
||||||
SqlWrapper.update(model, model.id, List.of("stepId", "log"));
|
SqlWrapper.update(model, model.id, List.of("stepId", "log"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -54,7 +53,7 @@ public class MigrationSqlStep implements MigrationInterface{
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user