(boolean baseline)
| 415 | } |
| 416 | |
| 417 | void execute0(boolean baseline) { |
| 418 | |
| 419 | // TODO: Transactions don't really make sense in most dialects. In some, they do |
| 420 | // e.g. PostgreSQL supports transactional DDL. Check if we're getting this right. |
| 421 | run(() -> { |
| 422 | DefaultMigrationContext ctx = migrationContext(baseline); |
| 423 | MigrationListener listener = new MigrationListeners(configuration); |
| 424 | |
| 425 | if (!FALSE.equals(dsl().settings().isMigrationAutoVerification())) |
| 426 | verify0(ctx); |
| 427 | |
| 428 | init(baseline); |
| 429 | |
| 430 | try { |
| 431 | listener.migrationStart(ctx); |
| 432 | int untracked = ctx.revertUntrackedQueries.queries().length; |
| 433 | |
| 434 | if (baseline) { |
| 435 | if (history.available() |
| 436 | && history.current().version().id().equals(to().id()) |
| 437 | && untracked == 0 |
| 438 | ) { |
| 439 | if (log.isInfoEnabled()) |
| 440 | log.info("Current version is already set to baseline version: " + to().id()); |
| 441 | |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | if (log.isInfoEnabled()) |
| 446 | log.info("Setting baseline to " + to().id()); |
| 447 | |
| 448 | if (untracked == 0) { |
| 449 | createRecord(ctx, SUCCESS, from(), to(), "New baseline"); |
| 450 | } |
| 451 | else { |
| 452 | if (log.isInfoEnabled()) |
| 453 | log.info("Reverting untracked changes (number of queries: " + untracked + ")"); |
| 454 | |
| 455 | StopWatch watch = new StopWatch(); |
| 456 | HistoryRecord record = createRecord(ctx, STARTING, from(), to(), "New baseline"); |
| 457 | |
| 458 | try { |
| 459 | log(watch, record, REVERTING); |
| 460 | revertUntracked(ctx, listener, record); |
| 461 | log(watch, record, SUCCESS); |
| 462 | } |
| 463 | catch (Exception e) { |
| 464 | StringWriter s = new StringWriter(); |
| 465 | e.printStackTrace(new PrintWriter(s)); |
| 466 | |
| 467 | if (log.isErrorEnabled()) |
| 468 | log.error("Setting " + to().id() + " as baseline failed: " + e.getMessage()); |
| 469 | |
| 470 | log(watch, record, FAILURE, OPEN, s.toString()); |
| 471 | throw new DataMigrationRedoLogException(record, e); |
| 472 | } |
| 473 | } |
| 474 |
no test coverage detected