Skip to content

Commit

Permalink
Fixed #1897: Info should also print the current schema version
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Fontaine committed Jan 16, 2018
1 parent d2d9f00 commit 97a429f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.MigrationInfoService;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.api.logging.Log;
import org.flywaydb.core.api.logging.LogFactory;
import org.flywaydb.core.internal.configuration.ConfigUtils;
Expand Down Expand Up @@ -161,7 +164,12 @@ private static void executeOperation(Flyway flyway, String operation) {
} else if ("validate".equals(operation)) {
flyway.validate();
} else if ("info".equals(operation)) {
LOG.info("\n" + MigrationInfoDumper.dumpToAsciiTable(flyway.info().all()));
MigrationInfoService info = flyway.info();
MigrationInfo current = info.current();
MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion();
LOG.info("Schema version: " + currentSchemaVersion);
LOG.info("");
LOG.info(MigrationInfoDumper.dumpToAsciiTable(info.all()));
} else if ("repair".equals(operation)) {
flyway.repair();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public int migrate() throws FlywayException {
for (final FlywayCallback callback : effectiveCallbacks) {
new TransactionTemplate(connectionUserObjects.getJdbcConnection()).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
public Object call() {
connectionUserObjects.changeCurrentSchemaTo(schema);
callback.beforeMigrate(connectionUserObjects.getJdbcConnection());
return null;
Expand Down Expand Up @@ -151,7 +151,7 @@ public Integer call() {
for (final FlywayCallback callback : effectiveCallbacks) {
new TransactionTemplate(connectionUserObjects.getJdbcConnection()).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
public Object call() {
connectionUserObjects.changeCurrentSchemaTo(schema);
callback.afterMigrate(connectionUserObjects.getJdbcConnection());
return null;
Expand Down Expand Up @@ -199,10 +199,8 @@ private Integer migrateGroup(boolean firstRun) {
new MigrationInfoServiceImpl(migrationResolver, schemaHistory, configuration.getTarget(), configuration.isOutOfOrder(), true, true, true);
infoService.refresh();

MigrationVersion currentSchemaVersion = MigrationVersion.EMPTY;
if (infoService.current() != null) {
currentSchemaVersion = infoService.current().getVersion();
}
MigrationInfo current = infoService.current();
MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion();
if (firstRun) {
LOG.info("Current version of schema " + schema + ": " + currentSchemaVersion);

Expand Down Expand Up @@ -295,7 +293,7 @@ private void applyMigrations(final LinkedHashMap<MigrationInfoImpl, Boolean> gro
if (executeGroupInTransaction) {
new TransactionTemplate(connectionUserObjects.getJdbcConnection()).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
public Object call() {
doMigrateGroup(group, stopWatch);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package org.flywaydb.gradle.task;

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.MigrationInfoService;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.internal.info.MigrationInfoDumper;

public class FlywayInfoTask extends AbstractFlywayTask {
Expand All @@ -26,7 +29,11 @@ public FlywayInfoTask() {

@Override
protected Object run(Flyway flyway) {
System.out.println(MigrationInfoDumper.dumpToAsciiTable(flyway.info().all()));
MigrationInfoService info = flyway.info();
MigrationInfo current = info.current();
MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion();
System.out.println("Schema version: " + currentSchemaVersion);
System.out.println(MigrationInfoDumper.dumpToAsciiTable(info.all()));
return null;
}
}
12 changes: 10 additions & 2 deletions flyway-maven-plugin/src/main/java/org/flywaydb/maven/InfoMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.MigrationInfoService;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.internal.info.MigrationInfoDumper;

/**
Expand All @@ -32,7 +35,12 @@
threadSafe = true)
public class InfoMojo extends AbstractFlywayMojo {
@Override
protected void doExecute(Flyway flyway) throws Exception {
log.info("\n" + MigrationInfoDumper.dumpToAsciiTable(flyway.info().all()));
protected void doExecute(Flyway flyway) {
MigrationInfoService info = flyway.info();
MigrationInfo current = info.current();
MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion();
log.info("Schema version: " + currentSchemaVersion);
log.info("");
log.info(MigrationInfoDumper.dumpToAsciiTable(info.all()));
}
}

0 comments on commit 97a429f

Please sign in to comment.