question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PostgreSQL Precondition sequenceExists is not working.

See original GitHub issue

Environment

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

  1. Apply DDL from db_ddl.txt
  2. Create sequence manually: CREATE SEQUENCE public.analytics_queue_id_seq START WITH 1 INCREMENT BY 1
  3. 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.

application.log

db_ddl.txt

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rios0rios0commented, Sep 2, 2022

Hey guys. This is still happening.

org.liquibase:liquibase-core:4.15.0
org.springframework.boot:spring-boot-starter-web:2.7.3
org.postgresql:postgresql:42.5.0

table_id_seq is a default sequence already created by the database.

author: 'rios0rios0'
      context: 'prod'
      preConditions:
        - sequenceExists:
            sequenceName: 'table_id_seq'

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

1reaction
bbendecommented, Jul 21, 2022

FWIW I have tested using this same type of preCondition with liquibase 4.9.1 and Postgres 13, and did not have any issue. The preCondition correctly determine the sequence existed and marked it as ran.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Liquibase preconditions with sequenceexists not working
I'm trying to run liquibase on existing db, at that i'm facing error sequence already exists <createSequence sequenceName="call_id_seq" ...
Read more >
[CORE-3366] Precondition sequenceExists is not working.
Precondition sequenceExists failed to check existing auto increment sequence. 2018-12-28 17:20:30.539 INFO 13697 — [ main] ...
Read more >
Preconditions | Liquibase Docs
Document what assumptions the author of the changelog had when creating it. Enforce that those assumptions are not violated by users running the...
Read more >
Check database state and conditionally apply changes in the ...
Preconditions can be attached to changelogs or changesets to control the execution of an update based on the state of the database. Types...
Read more >
PostgreSQL 12 Support - General Discussion - Liquibase Forum
Hello Experts Does liquibase support Postgres 12? I am getting the following error ... Started seeing this issues while testing for 12.x.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found