PostgreSQL Precondition sequenceExists is not working.
See original GitHub issueEnvironment
Liquibase Version: 3.6.2
Liquibase Integration & Version: spring boot
Liquibase Extension(s) & Version: n/a
Database Vendor & Version: PostgreSQL 10.6
Operating System Type & Version: Ubuntu 10.6-0ubuntu0.18.04.1
Description
Precondition sequenceExists failed to check existing auto increment sequence. Application log: 2018-12-28 17:20:30.539 INFO 13697 — [ main] liquibase.executor.jvm.JdbcExecutor : SELECT c.relname AS SEQUENCE_NAME FROM pg_class c join pg_namespace on c.relnamespace = pg_namespace.oid WHERE c.relkind=‘S’ AND nspname = ‘null’ AND c.oid not in (select d.objid FROM pg_depend d where d.refobjsubid > 0) 2018-12-28 17:20:30.544 INFO 13697 — [ main] liquibase.executor.jvm.JdbcExecutor : SELECT c.relname AS SEQUENCE_NAME FROM pg_class c join pg_namespace on c.relnamespace = pg_namespace.oid WHERE c.relkind=‘S’ AND nspname = ‘public’ AND c.oid not in (select d.objid FROM pg_depend d where d.refobjsubid > 0) 2018-12-28 17:20:30.548 INFO 13697 — [ main] liquibase.executor.jvm.JdbcExecutor : CREATE SEQUENCE public.analytics_queue_id_seq START WITH 1 INCREMENT BY 1 2018-12-28 17:20:30.550 ERROR 13697 — [ main] liquibase.changelog.ChangeSet : Change Set changelogs/6.xml::11::931@company.ru failed. Error: ERROR: relation “analytics_queue_id_seq” already exists [Failed SQL: CREATE SEQUENCE public.analytics_queue_id_seq START WITH 1 INCREMENT BY 1]
Changeset:
<changeSet id="11" author="931@company.ru">
<preConditions onFail="MARK_RAN">
<not>
<sequenceExists sequenceName="analytics_queue_id_seq"/>
</not>
</preConditions>
<createSequence sequenceName="analytics_queue_id_seq" incrementBy="1" startValue="1" />
<sql dbms="postgresql"> select setval('analytics_queue_id_seq', max(id)+1) from analytics_queue </sql>
<addDefaultValue tableName="analytics_queue" columnName="id" defaultValueSequenceNext="analytics_queue_id_seq"/>
<sql dbms="postgresql"> alter sequence analytics_queue_id_seq owned by analytics_queue.id; </sql>
</changeSet>
Steps To Reproduce
- Apply DDL from db_ddl.txt
- Create sequence manually: CREATE SEQUENCE public.analytics_queue_id_seq START WITH 1 INCREMENT BY 1
- Run the changeset migration.
Actual Behavior
Precondition <not><sequenceExists></not> passed successfully. Applying changeset failed, because sequence already exists.
See application.log
Expected/Desired Behavior
Precondition <not><sequenceExists></not> should be failed. Changeset should be marked as RAN and should not be applied.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Hey guys. This is still happening.
table_id_seq
is a default sequence already created by the database.Post of 5 years ago with the comment solving with a workaround: https://stackoverflow.com/questions/42414336/liquibase-preconditions-with-sequenceexists-not-working
Workaround: https://stackoverflow.com/a/28152899/10746857
FWIW I have tested using this same type of
preCondition
withliquibase 4.9.1
andPostgres 13
, and did not have any issue. ThepreCondition
correctly determine the sequence existed and marked it as ran.