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

#1154 - Drop functions with length attributes in DB2 #1155

Merged
merged 2 commits into from Jan 19, 2016

Conversation

@umefjord
Copy link

@umefjord umefjord commented Jan 8, 2016

FIX 1:
Patch to enable dropping functions in DB2 with datatypes that are not able to drop without parenthesis on the type, for example:

DROP FUNCTION MYFUNC(CHAR); --Fails => old implementation
DROP FUNCTION MYFUNC(CHAR()); --Succeeds => in this patch

Special case:

DROP FUNCTION MYFUNC(DECFLOAT); --Fails
DROP FUNCTION MYFUNC(DECFLOAT()); --Fails
DROP FUNCTION MYFUNC(DECFLOAT(16)); --Succeeds if length is 16 (can be 34) => not in this patch
DROP FUNCTION MYFUNC; --Succeeds, fallback workaround in this patch

FIX2:
Expression based indexes had to follow a special name convention in order to get flyway:clean to work.

CREATE TABLE CUSTOMER (
firstname VARCHAR(25) NOT NULL
);

CREATE INDEX IDX_CUSTOMER_NAME ON CUSTOMER(LOWER(FIRSTNAME) ASC); --Success (due to special case)
CREATE INDEX IX_CUSTOMER_NAME ON CUSTOMER(LOWER(FIRSTNAME) ASC); --Fail to clean
CREATE INDEX I_CUSTOMER_NAME ON CUSTOMER(LOWER(FIRSTNAME) ASC); --Fail to clean

mvn flyway:clean

Gives the following error:

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:3.2.1:clean (default-cli) on project db2flyway: org.flywaydb.core.api.FlywayException: Unable to clean
schema "DB2FLYWAY": DB2 SQL Error: SQLCODE=-658, SQLSTATE=42917, SQLERRMC=IX_CUSTOMER_NAME_V, DRIVER=4.19.26 -> [Help 1]

flyway:clean is trying to drop the materialized view that is created under the hood by the expression based index:

DROP VIEW IX_CUSTOMER_NAME_V; --Fail

...rather than dropping the index, i.e:

DROP INDEX IX_CUSTOMER_NAME; --Success

If the index name matches "IDX_%_V" it will succeed due to a special exclusion when views are fetched from SYSCAT. Not very robust and not compatible with other naming conventions.

The fix widens the special exclusion to match "%V" rather than "IDX%_V".

markus.umefjord@gmail.com added 2 commits Jan 8, 2016
…xes), such as

CREATE INDEX IX_CUSTOMER_NAME ON CUSTOMER(LOWER(FIRSTNAME) ASC);

Before they had to follow a special name convention (start with IDX_) to work correctly.
@axelfontaine axelfontaine added this to the Flyway 4.0 milestone Jan 19, 2016
axelfontaine added a commit that referenced this pull request Jan 19, 2016
#1154 - Drop functions with length attributes in DB2
@axelfontaine axelfontaine merged commit 28471e8 into flyway:master Jan 19, 2016
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Jan 19, 2016

Great work! Thanks! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants