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

flyway:clean doesnt remove check constraint #589

Closed
lrozek opened this issue Aug 22, 2013 · 7 comments
Closed

flyway:clean doesnt remove check constraint #589

lrozek opened this issue Aug 22, 2013 · 7 comments

Comments

@lrozek
Copy link
Contributor

@lrozek lrozek commented Aug 22, 2013

java.sql.SQLException: Cannot DROP FUNCTION 'dbo.CHECK_UNTERNEHMEN_OVERLAPPING_GFK' because it is being referenced by object 'U_C_UNTERNEHMEN_GFK_NUMMER'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372) ~[jtds-1.3.1.jar:1.3.1]
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988) ~[jtds-1.3.1.jar:1.3.1]
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421) ~[jtds-1.3.1.jar:1.3.1]
    at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:671) ~[jtds-1.3.1.jar:1.3.1]
    at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:613) ~[jtds-1.3.1.jar:1.3.1]
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:572) ~[jtds-1.3.1.jar:1.3.1]
    at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedStatement.java:784) ~[jtds-1.3.1.jar:1.3.1]
    at net.sf.log4jdbc.PreparedStatementSpy.execute(PreparedStatementSpy.java:417) ~[log4jdbc4-1.2.jar:na]
    at com.googlecode.flyway.core.dbsupport.JdbcTemplate.execute(JdbcTemplate.java:214) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.dbsupport.sqlserver.SQLServerSchema.doClean(SQLServerSchema.java:85) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.dbsupport.Schema.clean(Schema.java:148) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.command.DbClean$2.doInTransaction(DbClean.java:119) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.command.DbClean$2.doInTransaction(DbClean.java:117) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:56) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.command.DbClean.cleanSchema(DbClean.java:117) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.command.DbClean.clean(DbClean.java:81) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.Flyway$3.execute(Flyway.java:933) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.Flyway$3.execute(Flyway.java:929) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.Flyway.execute(Flyway.java:1200) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.core.Flyway.clean(Flyway.java:929) ~[flyway-core-2.2.1.jar:na]
    at com.googlecode.flyway.maven.CleanMojo.doExecute(CleanMojo.java:32) ~[flyway-maven-plugin-2.2.1.jar:na]
    at com.googlecode.flyway.maven.AbstractFlywayMojo.execute(AbstractFlywayMojo.java:251) ~[flyway-maven-plugin-2.2.1.jar:na]
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) ~[maven-core-3.0.5.jar:3.0.5]
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) ~[maven-embedder-3.0.5.jar:3.0.5]
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) ~[maven-embedder-3.0.5.jar:3.0.5]
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) ~[maven-embedder-3.0.5.jar:3.0.5]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) ~[plexus-classworlds-2.4.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) ~[plexus-classworlds-2.4.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) ~[plexus-classworlds-2.4.jar:na]
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) ~[plexus-classworlds-2.4.jar:na]
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Aug 22, 2013

Thanks for the report. Could you please post a small sample script that triggers the problem to make sure your case is covered by my tests? Also, which SQL Server version are you using?

Cheers
Axel

@lrozek
Copy link
Contributor Author

@lrozek lrozek commented Aug 22, 2013

no problem,

here is project for reproduction
https://github.com/lrozek/flyway-589

@lrozek
Copy link
Contributor Author

@lrozek lrozek commented Aug 22, 2013

I did quick fix in debugger while investigating the issue.
To fix it in SQLServerSchema.cleanForeignKeys
use following sql:
SELECT table_name, constraint_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS" +
" WHERE constraint_type constraint_type in ('FOREIGN KEY', 'CHECK') and table_schema=?

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Aug 22, 2013

Thank you for investigating this!

Would you like to provide a pull request with a test and the method renamed to cleanContraints() ?

Cheers
Axel

@lrozek
Copy link
Contributor Author

@lrozek lrozek commented Aug 22, 2013

sure, I try to do it on a weekend

@lrozek
Copy link
Contributor Author

@lrozek lrozek commented Sep 16, 2013

here it is
#605

cheers
Lukasz

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Sep 17, 2013

Thank you so much!! Merged.

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