示例#1
0
 private void apply(DataSource ds, Migration migration, Optional<Integer> version) {
   Jdbc.inTransaction(
       ds,
       connection -> {
         Migrater.current.set(connection);
         log.info("Applying {}: {}", migration.getClass().getSimpleName(), migration.toString());
         // Set the updater in case any history triggers are listening
         Jdbc.update(connection, "set @updater=?", migration.getClass().getSimpleName());
         try {
           migration.apply();
         } catch (SQLException se) {
           throw new JdbcException(se);
         }
         // Tick to the current version number
         version.ifPresent(v -> this.schemaInfoTable.updateVersionNumber(connection, v));
         Jdbc.update(connection, "set @updater=null");
         return null;
       });
 }
示例#2
0
 private void applyNormalMigrations(DataSource ds) {
   int version = Jdbc.inTransaction(ds, c -> this.schemaInfoTable.nextVersionNumber(c));
   while (true) {
     Optional<Migration> migration = this.migrationClasses.get("m", version);
     if (migration.isPresent()) {
       this.apply(ds, migration.get(), Optional.of(version));
       version++;
     } else {
       break;
     }
   }
 }