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
Clean fails when Postgres DOMAIN depends on SEQUENCE #1802
Comments
The problem is here: Line 87 in ac266f4
PostgreSQLSchema.doClean() is cleaning sequences before domains. It should clean sequences after domains since domains can depend on sequences via the DEFAULT clause. |
Workaround: in beforeClean.sql do this: DROP SEQUENCE IF EXISTS foo_seq CASCADE; This will drop the sequence and everything that depends on it (including the domain depending on it, and any types/tables/routines depending on that domain). |
This is a more generic workaround, it works no matter what the sequences are named. Add the following to beforeClean.sql: DO LANGUAGE plpgsql $$ DECLARE
v_sql TEXT;
BEGIN
FOR v_sql IN (SELECT FORMAT('DROP SEQUENCE %I CASCADE', SEQUENCE_NAME)
FROM INFORMATION_SCHEMA.SEQUENCES
WHERE SEQUENCE_SCHEMA = CURRENT_SCHEMA) LOOP
EXECUTE v_sql;
END LOOP;
END;
$$; |
Good catch and thank you very much for the investigation! Fixed. |
What version of Flyway are you using?
Flyway 4.2.0
Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin, SBT plugin, ANT tasks)
Reproduced issue with command line client.
(But I am using Java API in my code)
What database are you using (type & version)?
PostgreSQL 9.6.5
What operating system are you using?
macOS 10.12.6
What did you do?
(Please include the content causing the issue, any relevant configuration settings, and the command you ran)
What did you expect to see?
"flyway clean" successfully cleans schema
What did you see instead?
Database: jdbc:postgresql://localhost/flybug (PostgreSQL 9.6)
ERROR:
Unable to clean schema "public"
SQL State : 2BP01
Error Code : 0
Message : ERROR: cannot drop sequence foo_seq because other objects depend on it
Detail: type foo_seq_dom depends on sequence foo_seq
Hint: Use DROP ... CASCADE to drop the dependent objects too.
The text was updated successfully, but these errors were encountered: