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

Support for tnsnames.ora if TNS_ADMIN is set (issue #1806) does not work correctly. #1979

Closed
Forinil opened this issue Apr 10, 2018 · 1 comment

Comments

@Forinil
Copy link

Forinil commented Apr 10, 2018

Which version and edition of Flyway are you using?

5.0.5

If this is not the latest version, can you reproduce the issue with the latest one as well?

(Many bugs are fixed in newer releases and upgrading will often resolve the issue)

Judging by the source code - yes

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Command-line

Which database are you using (type & version)?

Oracle 12c

Which operating system are you using?

Windows 7

What did you do?

(Please include the content causing the issue, any relevant configuration settings, the SQL statement that failed (if relevant) and the command you ran.)

  1. Set up variable TNS_ADMIN to location of my tnsnames.ora file
  2. Run flyway migrate with JDBC URL set tu use TNS name of my DB connection
What did you expect to see?

Message about successfully completed migration

What did you see instead?

ERROR: Unable to obtain connection from database

What do you suspect happened?

Method org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(Configuration, boolean):

  1. Opens the connection.
  2. Obtains database product name from connection
  3. Creates an instance of appropriate sublcass of class org.flywaydb.core.internal.database.Database (in this case org.flywaydb.core.internal.database.oracle.OracleDatabase).

However, when using TNS, the database connection cannot be opened (step 1) when System property "oracle.net.tns_admin" is not set - and that property is set based on TNS_ADMIN environment variable in step 3.

What solution do you propose?

I would propose moving this code:

String tnsAdminEnvVar = System.getenv("TNS_ADMIN");
String tnsAdminSysProp = System.getProperty(ORACLE_NET_TNS_ADMIN);
 if (StringUtils.hasLength(tnsAdminEnvVar) && tnsAdminSysProp == null) {
     System.setProperty(ORACLE_NET_TNS_ADMIN, tnsAdminEnvVar);
}

from constructor of class org.flywaydb.core.internal.database.oracle.OracleDatabase to the beginning of method org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(Configuration, boolean)

@axelfontaine axelfontaine added this to the Flyway 5.1.0 milestone Apr 10, 2018
axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Apr 10, 2018
@axelfontaine
Copy link
Contributor

Good catch and thanks for investigating! Fixed.

dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants