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

Better support for DDL statements that cannot run within a transaction #851

Closed
pards opened this issue Sep 30, 2014 · 11 comments
Closed

Better support for DDL statements that cannot run within a transaction #851

pards opened this issue Sep 30, 2014 · 11 comments

Comments

@pards
Copy link

pards commented Sep 30, 2014

Overriding DbSupport.supportsDdlTransactions does not prevent FlyWay from attempting to execute DDL statements in a transaction.

I was trying to implement Netezza support, but found that ALTER TABLE statements fail when executed in a transaction.

See
http://www-01.ibm.com/support/knowledgecenter/SSULQD_7.1.0/com.ibm.nz.dbu.doc/r_dbuser_ntz_sql_func_categories_transaction_control.html

@pards
Copy link
Author

pards commented Sep 30, 2014

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:0-SNAPSHOT:migrate (default-cli) on project rdr-database: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException: Error executing statement at line 1: alter table person
[ERROR] add name varchar(30): ERROR:  Add column may not be called in a transaction block or an autocommit off block of a stored procedure
[ERROR] -> [Help 1]
[ERROR]

Despite having this in NetezzaDbSupport.java

@Override
public boolean supportsDdlTransactions() {
    // NZ doesn't fully support all DDL operation in transactions, i.e. alter table
    return false;
}

@axelfontaine
Copy link
Contributor

As per JavaDoc: Checks whether ddl transactions are supported for this database.

It is purely informative, as to how to behave in case of failure.

Which DDL statement is failing? Is it part of a regular migration? What other limitations does Netezza have? (Not all abstractions to support them may be present in the core yet)

@axelfontaine
Copy link
Contributor

Any news?

@pards
Copy link
Author

pards commented Oct 19, 2014

ALTER TABLE statements fail
It's part of a regular migration.

See the Netezza documentation for further information.
http://www-01.ibm.com/support/knowledgecenter/SSULQD_7.1.0/com.ibm.nz.dbu.doc/r_dbuser_ntz_sql_func_categories_transaction_control.html

Basically, the following list of statements are NOT permitted within a transaction

  • BEGIN
  • [CREATE | DROP] DATABASE
  • ALTER TABLE [ADD | DROP] COLUMN operations
  • SET AUTHENTICATION
  • [SET | DROP] CONNECTION
  • GROOM TABLE
  • GENERATE STATISTICS
  • SET SYSTEM DEFAULT HOSTKEY
  • [CREATE | ALTER|DROP] KEYSTORE
  • [CREATE | DROP] CRYPTO KEY
  • SET CATALOG
  • SET SCHEMA dbname.schemaname, where dbname is not the current database

@axelfontaine
Copy link
Contributor

Ok, thanks. Let's revisit this in the 3.2 timeframe to see if the necessary abstractions can be put in place to make this easier to implement.

@axelfontaine axelfontaine added this to the Flyway 3.2 milestone Oct 20, 2014
@axelfontaine axelfontaine changed the title supportsDdlTransactions not honored Better support for DDL statements that cannot run within a transaction Nov 26, 2014
@kryptt
Copy link

kryptt commented Feb 27, 2015

Is there currently any way to get arround this ?

I am getting ERROR: ALTER TYPE ... ADD cannot run inside a transaction block for a postgres migration myself..

@pards
Copy link
Author

pards commented Feb 27, 2015

Not to my knowledge.
Netezza is forked from Postgres, so it sounds like the same problem

@kryptt
Copy link

kryptt commented Feb 27, 2015

I stumbled onto the limitations section of the postgres page for your docs:
http://flywaydb.org/documentation/database/postgresql.html

and managed to re-write the query in a transaction safe way (pasting it here, if someone else stumbles across this:

ALTER TYPE action_type RENAME TO stale_action_type;

CREATE TYPE action_type AS ENUM(
  'loginFailure',
  'loginSuccess',
  ...
);

ALTER TABLE mytable ALTER COLUMN action TYPE action_type USING action::text::action_type;

DROP TYPE stale_action_type;

@axelfontaine axelfontaine modified the milestones: Flyway 4.0, Flyway 3.2 Mar 4, 2015
@axelfontaine axelfontaine modified the milestones: Flyway 4.1, Flyway 4.0 Dec 30, 2015
@trygvis
Copy link

trygvis commented Feb 10, 2016

@kryptt Thanks!

For the archive, you can use full expressions for the USING clause:

ALTER TABLE foo
ALTER COLUMN bar TYPE new_type USING (
CASE bar :: TEXT
WHEN 'AAA'
  THEN 'BBB'
ELSE bar :: TEXT END) :: new_type;

@realsonic
Copy link

@kryptt Thanks a lot for W/A. I have the same problem too.

@axelfontaine
Copy link
Contributor

This has been fixed for PostgreSQL via auto-detection. Please open new issues for other databases.

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

5 participants