Numerous flaws in Clean implementation for Oracle DB #1550
Comments
#1306 can be fixed as part of this issue |
Thanks for pointing this out. One pull request per flaw would be awesome as it would make them easy to analyse and therefore quicker to get accepted. |
The method that evaluates if flashback is available or not is not correct. It checks that DBA_FLASHBACK_ARCHIVE_TABLES exists in all_objects but it does not verify that the user has access to it. In case the user cannot select from that table, flyway.clean will fail with "ORA--00942: table or view does not exist". |
@gpolet It is granted to PUBLIC. Have you encountered this issue? I will add a check for accessibility anyway. |
@vosolovskiy Hi, thanks for the quick feedback. I indeed faced this problem in Oracle. Not sure exactly why this differs from your situation in my Oracle installation. This might have been imposed by our DBA's. |
@vosolovskiy Thanks again for the fantastic contribution. Truly appreciated! |
Flaws in Clean phase:
select schema, other_schemas from dba_registry
.defaultSchemaForUser
is computed wrongly: it shouldn't ignore case when compares the schema name with the deploy user name, because schema names are always quoted in the Flyway code (which is correct).OracleDbSupport#doCurrentSchemaName
method is wrong: the correct SQL should beSELECT SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA') FROM DUAL
. New methods should be added toDbSupport
class and its inheritors:getCurrentUser
anddoGetCurrentUser
, which by default can returnjdbcTemplate.getMetaData().getUserName()
(which is not precise) and should be overridden. For Oracle it'sSELECT USER FROM DUAL
. This new method must be used for computingdefaultSchemaForUser
flag named above instead ofdoCurrentSchemaName
.OracleDbSupport#doAllTables
to fix #178 is fallible. It should be corrected. There's no use to count references. Instead this graph should be traversed in correct direction.doClean()
method should be refactored (and this remark is related to all theSchema
implementations): there are a lot code duplication (repeated typical for-loops) and violation of SRP (clean logic for each and every object type/metadata is stored in the same class). This makesdoClean()
less supportable.Flaws not directly related to Clean phase but noticed in the mentioned classes:
count(*)
for checking whether a query returns rows is not efficient. This should be replaced withexists(...)
SQL function or a new method in JdbcTemplate class, which would only check and return.next()
on the returned ResultSet of a queryI can fix all these issues.
The text was updated successfully, but these errors were encountered: