From e7485193ea0fb8a598bb0fee3424a43ca2aa2f3d Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Thu, 12 Oct 2017 02:45:53 +0900 Subject: [PATCH] fixes #84 Add a new per-environment option 'ignoreWarnings'. If set to true, a warning raised by the database is ignored and migration continues. --- .../java/org/apache/ibatis/migration/Environment.java | 8 +++++++- .../org/apache/ibatis/migration/commands/BaseCommand.java | 2 +- .../ibatis/migration/template_environment.properties | 5 ++++- src/site/xdoc/init.xml | 3 +++ src/site/xdoc/migrate.xml | 4 ++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/ibatis/migration/Environment.java b/src/main/java/org/apache/ibatis/migration/Environment.java index 67d7fc68..866ba66b 100644 --- a/src/main/java/org/apache/ibatis/migration/Environment.java +++ b/src/main/java/org/apache/ibatis/migration/Environment.java @@ -32,7 +32,7 @@ public class Environment { public static final String CHANGELOG = "changelog"; private enum SETTING_KEY { - time_zone, delimiter, script_char_set, full_line_delimiter, send_full_script, auto_commit, remove_crs, driver_path, driver, url, username, password, hook_before_up, hook_before_each_up, hook_after_each_up, hook_after_up, hook_before_down, hook_before_each_down, hook_after_each_down, hook_after_down + time_zone, delimiter, script_char_set, full_line_delimiter, send_full_script, auto_commit, remove_crs, ignore_warnings, driver_path, driver, url, username, password, hook_before_up, hook_before_each_up, hook_after_each_up, hook_after_up, hook_before_down, hook_before_each_down, hook_after_each_down, hook_after_down } private static final List SETTING_KEYS; @@ -53,6 +53,7 @@ private enum SETTING_KEY { private final boolean sendFullScript; private final boolean autoCommit; private final boolean removeCrs; + private final boolean ignoreWarnings; private final String driverPath; private final String driver; private final String url; @@ -84,6 +85,7 @@ public Environment(File file) { this.sendFullScript = Boolean.valueOf(prop.getProperty(SETTING_KEY.send_full_script.name())); this.autoCommit = Boolean.valueOf(prop.getProperty(SETTING_KEY.auto_commit.name())); this.removeCrs = Boolean.valueOf(prop.getProperty(SETTING_KEY.remove_crs.name())); + this.ignoreWarnings = Boolean.valueOf(prop.getProperty(SETTING_KEY.ignore_warnings.name())); this.driverPath = prop.getProperty(SETTING_KEY.driver_path.name()); this.driver = prop.getProperty(SETTING_KEY.driver.name()); @@ -151,6 +153,10 @@ public boolean isRemoveCrs() { return removeCrs; } + public boolean isIgnoreWarnings() { + return ignoreWarnings; + } + public String getDriverPath() { return driverPath; } diff --git a/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java b/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java index 21cfc560..8b824a15 100644 --- a/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java +++ b/src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java @@ -325,7 +325,7 @@ protected DatabaseOperationOption getDatabaseOperationOption() { DatabaseOperationOption option = new DatabaseOperationOption(); option.setChangelogTable(changelogTable()); option.setStopOnError(!options.isForce()); - option.setThrowWarning(!options.isForce()); + option.setThrowWarning(!options.isForce() && !environment().isIgnoreWarnings()); option.setEscapeProcessing(false); option.setAutoCommit(environment().isAutoCommit()); option.setFullLineDelimiter(environment().isFullLineDelimiter()); diff --git a/src/main/java/org/apache/ibatis/migration/template_environment.properties b/src/main/java/org/apache/ibatis/migration/template_environment.properties index 7c568e4e..1bb0ddf2 100644 --- a/src/main/java/org/apache/ibatis/migration/template_environment.properties +++ b/src/main/java/org/apache/ibatis/migration/template_environment.properties @@ -1,5 +1,5 @@ # -# Copyright 2010-2016 the original author or authors. +# Copyright 2010-2017 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -64,6 +64,9 @@ full_line_delimiter=false # but some do. auto_commit=false +# If set to true, warnings from the database do not interrupt migrations. +ignore_warnings=false + # Custom driver path to allow you to centralize your driver files # Default requires the drivers to be in the drivers directory of your # initialized migration directory (created with "migrate init") diff --git a/src/site/xdoc/init.xml b/src/site/xdoc/init.xml index 3241e764..0270ca47 100644 --- a/src/site/xdoc/init.xml +++ b/src/site/xdoc/init.xml @@ -91,6 +91,9 @@ full_line_delimiter=false # Use with JDBC drivers that can accept large # blocks of delimited text at once. send_full_script=false +# If set to true, warnings from the database +# do not interrupt migrations. +ignore_warnings=false # Custom driver path to avoid copying your drivers # driver_path=]]> diff --git a/src/site/xdoc/migrate.xml b/src/site/xdoc/migrate.xml index 0ae009e4..7de6e184 100644 --- a/src/site/xdoc/migrate.xml +++ b/src/site/xdoc/migrate.xml @@ -1,7 +1,7 @@