Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

informational message from database logged at WARN level #774

Closed
absurdhero opened this issue Jun 6, 2014 · 2 comments
Closed

informational message from database logged at WARN level #774

absurdhero opened this issue Jun 6, 2014 · 2 comments

Comments

@absurdhero
Copy link
Contributor

@absurdhero absurdhero commented Jun 6, 2014

PostgreSQL causes SQLWarnings when DDL statements have side-effects. In these cases, the SQLState and ErrorCode are both zero. According to SQL-92, a SQLState of 00 means success.
Since All SQLWarning objects are logged by flyway at the WARN level, it makes it difficult to filter out non-errors and appears confusing to end-users. Logging successful states at the INFO level would be more helpful.

The relevant logging code is in org.flywaydb.core.internal.dbsupport.JdbcTemplate.executeStatement()

Reproduction:

v_1__foo.sql:

CREATE TABLE foo (id int);
ALTER TABLE foo ADD CONSTRAINT foo_pkey PRIMARY KEY (id);

log message:

WARN o.f.c.i.dbsupport.JdbcTemplate - ALTER TABLE / ADD PRIMARY KEY will create implicit index "foo_pkey" for table "foo" (SQL State: 00000 - Error Code: 0)

@absurdhero
Copy link
Contributor Author

@absurdhero absurdhero commented Jun 7, 2014

I'm attempting to test a patch but the documented way of omitting commercial databases doesn't seem to work.

I tried mvn install -PNoInstallableDBTest -P-CommercialDBJars from the root of the project as documented on http://flywaydb.org/contribute/code/database.html and I also tried from within the flyway-core submodule. In either case, maven warned that, "The requested profile "NoInstallableDBTest" could not be activated because it does not exist." It also failed to build because it tried to include commercial jar dependencies which I don't have access to.

@absurdhero
Copy link
Contributor Author

@absurdhero absurdhero commented Jun 24, 2014

Since I can't build against master, I forked flyway-3.0 and applied a patch. It seems to be correctly logging information messages at the INFO level with my software.

I'll paste the patch here. Feel free to apply it. I can submit a pull request once it is possible to build master again.

diff --git a/flyway-core/src/main/java/org/flywaydb/core/internal/dbsupport/JdbcTemplate.java b/flyway-core/src/main/java/org/flywaydb/core/internal/dbsupport/JdbcTemplate.java
index 47fffb6..bdf8bb9 100644
--- a/flyway-core/src/main/java/org/flywaydb/core/internal/dbsupport/JdbcTemplate.java
+++ b/flyway-core/src/main/java/org/flywaydb/core/internal/dbsupport/JdbcTemplate.java
@@ -235,8 +235,12 @@ public class JdbcTemplate {
             statement.execute(sql);
             @SuppressWarnings("ThrowableResultOfMethodCallIgnored") SQLWarning warning = statement.getWarnings();
             while (warning != null) {
-                LOG.warn(warning.getMessage()
-                        + " (SQL State: " + warning.getSQLState() + " - Error Code: " + warning.getErrorCode() + ")");
+                if ("00000".equals(warning.getSQLState())) {
+                    LOG.info(warning.getMessage());
+                } else {
+                    LOG.warn(warning.getMessage()
+                            + " (SQL State: " + warning.getSQLState() + " - Error Code: " + warning.getErrorCode() + ")");
+                }
                 warning = warning.getNextWarning();
             }
         } finally {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.