MCPcopy Create free account
hub / github.com/UniversaBlockchain/universa / createDB

Method createDB

common_tools/src/main/java/com/icodici/db/Db.java:255–286  ·  view source on GitHub ↗
(final String migrationResource)

Source from the content-addressed store, hash-verified

253 }
254
255 public void createDB(final String migrationResource) {
256 if (migrationResource == null)
257 return;
258 try {
259 myVersion = 0;
260 try {
261 Integer v = queryOne("SELECT ivalue FROM vars WHERE name = 'version'");
262 if (v != null)
263 myVersion = v;
264 } catch (SQLException e) {
265 if (e.getMessage().indexOf("vars") < 0)
266 e.printStackTrace();
267 }
268 currentDbVersion = detectMaxMigrationVersion(migrationResource);
269 log.d("My db version is %d current is %d", myVersion, currentDbVersion);
270 while (myVersion < currentDbVersion) transaction(() -> {
271 log.d("Migrating to %d", myVersion + 1);
272 preMigrate(myVersion);
273 executeFile(migrationResource + myVersion + ".sql");
274 postMigrate(myVersion);
275 myVersion++;
276 update("update vars set ivalue=? where name='version'", myVersion);
277 return null;
278 });
279 } catch (RuntimeException e) {
280 throw e;
281 } catch (Exception e) {
282 e.printStackTrace();
283 throw new RuntimeException("migrations failed", e);
284 }
285 log.d("Db migrated successfully");
286 }
287
288 private int detectMaxMigrationVersion(String migrationResource) {
289 if (migrationResource == null || migrationResource.length() == 0)

Callers 1

setupDatabaseMethod · 0.95

Calls 9

queryOneMethod · 0.95
transactionMethod · 0.95
preMigrateMethod · 0.95
executeFileMethod · 0.95
postMigrateMethod · 0.95
updateMethod · 0.95
getMessageMethod · 0.45
dMethod · 0.45

Tested by

no test coverage detected