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

Existing indexes and unique constraints are dropped then recreated again. #436

Closed
DejfCold opened this issue Oct 5, 2022 · 45 comments · Fixed by #468 or #679
Closed

Existing indexes and unique constraints are dropped then recreated again. #436

DejfCold opened this issue Oct 5, 2022 · 45 comments · Fixed by #468 or #679
Assignees

Comments

@DejfCold
Copy link

DejfCold commented Oct 5, 2022

Environment

Liquibase Version: 4.16.1 (also 4.10.0)

Liquibase Integration & Version: Gradle

Liquibase Extension(s) & Version: org.liquibase.gradle:2.1.1, org.liquibase.ext:liquibase-hibernate5:4.16.1

Database Vendor & Version: PostgreSQL 14.2

Operating System Type & Version: Fedora Linux 36

Infrastructure Type/Provider: local PC & DB in Docker

Description

We've created some indexes using JPA's Index annotation. LB succesfully created those indexes in the DB. However when we run the diffChangelog Gradle task again (after the former changes are already in the DB), LB is trying to drop and recreate the indexes again. It does the same thing for unique constraints as well. I've found a related, but already resolved liquibase/liquibase#2069.

For example, in one CL it does this:

    <changeSet author="dejfcold (generated)" id="1664914383324-1">
        <createIndex indexName="table_name_column_name_idx" tableName="table_name" unique="false">
            <column name="column_name"/>
        </createIndex>
    </changeSet>
    
    <changeSet author="dejfcold (generated)" id="1664914383324-2">
        <addUniqueConstraint columnNames="id" constraintName="UC_TABLE_NAMEID_COL" tableName="table_name"/>
    </changeSet>

then in the next one it does this:

    <changeSet author="dejfcold (generated)" id="1664930693277-1">
        <dropIndex indexName="table_name_column_name_idx" tableName="table_name"/>
    </changeSet>
    <changeSet author="dejfcold (generated)" id="1664930693277-2">
        <createIndex indexName="table_name_column_name_idx" tableName="table_name" unique="false">
            <column name="column_name"/>
        </createIndex>
    </changeSet>

    <changeSet author="dejfcold (generated)" id="1664930693277-3">
        <dropUniqueConstraint constraintName="UC_TABLE_NAMEID_COL" tableName="table_name"/>
    </changeSet>
    <changeSet author="dejfcold (generated)" id="1664930693277-4">
        <addUniqueConstraint columnNames="id" constraintName="UC_TABLE_NAMEID_COL" tableName="table_name"/>
    </changeSet>

Steps To Reproduce

I have tried to create a sample app, but I couldn't reproduce it there.

Steps we do in our app:

  1. have existing app
  2. add the following entity:
package cz.dejfcold.demo

import java.util.*
import javax.persistence.*

@Entity
@Table(
    name = "some_table"
)
class SomeTable(
    @Id
    @Column(unique = true)
    var id: UUID,

    @Column
    var indexedColumn: String
)
  1. build the app
  2. run diffChangelog Gradle task
  3. run the app so it applies the changeset onto the DB
  4. apply the following change:
Index: src/main/kotlin/cz/dejfcold/demo/SomeTable.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/kotlin/cz/dejfcold/demo/SomeTable.kt b/src/main/kotlin/cz/dejfcold/demo/SomeTable.kt
--- a/src/main/kotlin/cz/dejfcold/demo/SomeTable.kt	
+++ b/src/main/kotlin/cz/dejfcold/demo/SomeTable.kt
@@ -5,7 +5,10 @@
 
 @Entity
 @Table(
-    name = "some_table"
+    name = "some_table",
+    indexes = [
+        Index(name = "some_index", columnList = "indexedColumn", unique = false)
+    ]
 )
 class SomeTable(
     @Id
  1. build the app
  2. run diffChangelog Gradle task again
  3. run the app so it applies the changeset onto the DB
  4. run diffChangelog Gradle task yet again
  5. observe the newest changeset where LB drops and recreates the index

Actual Behavior

Drops then creates the same new index and/or unique constraints.

Expected/Desired Behavior

If there was no other change, I'd expect an empty change set. If there was a change somewhere else, I'd expect it not touching unrelated things and only creating the changeset for the affected changes.

Additional Context

It doesn't do that with all indexes/unique constraints. Only to some. But both entities are made the same way and the only differences are the names and number of columns.

related issues:

@kevin-atx kevin-atx transferred this issue from liquibase/liquibase Oct 5, 2022
@matej-staron
Copy link

Seeing the same issue with Liquibase 4.16.1, MySQL 8 and Maven.

@fleboulch
Copy link
Contributor

fleboulch commented Jan 20, 2023

I have the same issue using liquibase 4.19.0 and maven.

Full descripton (configratuion, steps to reproduce, actual and expected behaviour) is written in PR description:

@andreyBelov
Copy link

andreyBelov commented Feb 12, 2023

I have same issue
<liquibase.version>4.18.0</liquibase.version>
<liquibase-hibernate6.version>4.18.0</liquibase-hibernate6.version>
It would be great to fix, because liquibase:diff with its changelog script generation is a fantastic tool

@fleboulch
Copy link
Contributor

@filipelautert can you help on this? I opened an MR to highlight the current issue

@filipelautert filipelautert self-assigned this Feb 13, 2023
@filipelautert filipelautert moved this from New to Planned in Liquibase Open Source Feb 27, 2023
@filipelautert filipelautert moved this from Planned to Foundation Team Tickets in Liquibase Open Source Mar 1, 2023
@filipelautert filipelautert removed their assignment Mar 7, 2023
@MalloD12 MalloD12 moved this from Foundation Team Tickets to Development in Liquibase Open Source Mar 13, 2023
@MalloD12
Copy link
Contributor

Hi @DejfCold , would you mind fetching the branch created in this PR and trying again?

@fleboulch I tried running the tests with the changes you made on User.hbm.xml and all the tests passed.

Thanks,
Daniel.

@DejfCold
Copy link
Author

Hi @MalloD12 , I'd like to, but I don't have access to the project anymore. I'm also not sure (from top of my head at least) how would I do that, since we used it from Gradle and couldn't reproduce it on fresh project. I'll try mentioning @sitole and also ask him using some other channels if he can try it out instead.

@MalloD12
Copy link
Contributor

Hi @sitole - @matej-staron - @andreyBelov: would you mind trying again with these PR changes? I think this should be fine, but would like to know if there is any other use case which might require any additional change.

Thanks,
Daniel.

@fleboulch
Copy link
Contributor

The issue is still here when we are using liquibase 4.22.0

@filipelautert
Copy link
Collaborator

As per @fleboulch comment, this still an issue.

@filipelautert filipelautert reopened this Jun 21, 2023
@github-project-automation github-project-automation bot moved this from Done to Candidate in Liquibase Open Source Jun 21, 2023
@kevin-atx kevin-atx moved this from Candidate to Planned in Liquibase Open Source Jun 30, 2023
@filipelautert filipelautert moved this from Planned to Foundation Team Tickets in Liquibase Open Source Jul 5, 2023
@filipelautert
Copy link
Collaborator

@siddharthapd sorry, not yet.

@jonenst
Copy link
Contributor

jonenst commented Feb 9, 2024

hi @filipelautert , I think I have the same problem, reproduced here:
liquibasebug_diffchangelog_unique_changeset_order.zip

In this repro we diff the source code to the current chngelog (using a dummy h2 database). There should be no generated changesets because they match. But for some equivalent changesets configurations it wronlgy generates DropUniqueConstraint AddUniqueConstraint (the same one) pairs. You can even add those changesets to the changelog and it still generates the same ones over and over again.

# the bad one does createTable, addColumn (in a separate changeset), addForeignKeyConstraint, addUniqueConstraint
$ mvn  clean compile liquibase:update liquibase:diff
[INFO] changeSets count: 2

# edit  src/main/resources/db/changelog/db.changelog-master.yaml to use changelog_good instead changelog_bad
# the good one does addUniqueConstraint before addForeignKeyConstraint instead of after
$ mvn  clean compile liquibase:update liquibase:diff
[INFO] changeSets count: 0

my setup is

@Entity
@Table
class ParentEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column
    private UUID id;

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "fooId_id",
            referencedColumnName = "id",
            foreignKey = @ForeignKey(
                    name = "fooId_id_fk"
            ), nullable = true)
    ChildEntity foo;

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "barId_id",
            referencedColumnName = "id",
            foreignKey = @ForeignKey(
                    name = "barId_id_fk"
            ), nullable = true)
    ChildEntity bar;

}

@Entity
@Table
class ChildEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column
    private UUID id;
}

the bad changelog:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
    <changeSet author="harperjon (generated)" id="1707499031054-1">
        <createTable tableName="child_entity">
            <column name="id" type="UUID">
                <constraints nullable="false" primaryKey="true" primaryKeyName="child_entityPK"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="harperjon (generated)" id="1707499031054-2">
        <createTable tableName="parent_entity">
            <column name="id" type="UUID">
                <constraints nullable="false" primaryKey="true" primaryKeyName="parent_entityPK"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="harperjon (generated)" id="1707499067649-1">
        <addColumn tableName="parent_entity">
            <column name="bar_id_id" type="uuid"/>
        </addColumn>
    </changeSet>
    <changeSet author="harperjon (generated)" id="1707499067649-2">
        <addColumn tableName="parent_entity">
            <column name="foo_id_id" type="uuid"/>
        </addColumn>
    </changeSet>
    <changeSet author="harperjon (generated)" id="1707499067649-5">
        <addForeignKeyConstraint baseColumnNames="bar_id_id" baseTableName="parent_entity" constraintName="barId_id_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="child_entity" validate="true"/>
    </changeSet>
    <changeSet author="harperjon (generated)" id="1707499067649-6">
        <addForeignKeyConstraint baseColumnNames="foo_id_id" baseTableName="parent_entity" constraintName="fooId_id_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="child_entity" validate="true"/>
    </changeSet>
    <changeSet author="harperjon (generated)" id="1707499067649-3">
        <addUniqueConstraint columnNames="bar_id_id" constraintName="UC_PARENT_ENTITYBAR_ID_ID_COL" tableName="parent_entity"/>
    </changeSet>
    <changeSet author="harperjon (generated)" id="1707499067649-4">
        <addUniqueConstraint columnNames="foo_id_id" constraintName="UC_PARENT_ENTITYFOO_ID_ID_COL" tableName="parent_entity"/>
    </changeSet>
</databaseChangeLog>

In my changelog the columns are added in separate changesets because in my case they were added after the entity was created.

Can you reproduce the issue ? Can I do something to help ?

I saw in the debugger in stepping in liquibase code that some indexes were considered readonly but couldn't understand enough of what was happening to find the root cause of the problem
Cheers

@Guschtel
Copy link
Contributor

I can confirm we still have such an issue with liquibase-hibernate 4.25.0

Basically it drops all PK and FK Constraints and creates them again.

Examples of generated Sql (we add the dbms:oracle) afterwards:

-- changeset hermchr:1707764571097-1 dbms:oracle
ALTER TABLE FALL_GNR DROP CONSTRAINT FK_FALL_ID;

-- changeset hermchr:1707764571097-3 dbms:oracle
ALTER TABLE FALL_GNR DROP CONSTRAINT FK_GNR_ID;

-- changeset hermchr:1707764571097-2 dbms:oracle
ALTER TABLE FALL_GNR ADD CONSTRAINT FK_FALL_ID FOREIGN KEY (FALL_ID) REFERENCES FALL (ID);

-- changeset hermchr:1707764571097-4 dbms:oracle
ALTER TABLE FALL_GNR ADD CONSTRAINT FK_GNR_ID FOREIGN KEY (GNR_ID) REFERENCES GNR (ID);

-- changeset hermchr:1707764571097-5 dbms:oracle
ALTER SEQUENCE SEQ_FALL INCREMENT BY 1;

-- changeset hermchr:1707764571097-6 dbms:oracle
ALTER SEQUENCE SEQ_FALL_GNR INCREMENT BY 1;

-- changeset hermchr:1707764571097-7 dbms:oracle
ALTER SEQUENCE SEQ_GNR INCREMENT BY 1;

-- changeset hermchr:1707764571097-8 dbms:oracle
ALTER SEQUENCE SEQ_ICD_CODE_GEN INCREMENT BY 1;

-- changeset hermchr:1707764571097-9 dbms:oracle
ALTER TABLE FALL DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-10 dbms:oracle
CREATE INDEX FALLPK ON FALL(ID);

-- changeset hermchr:1707764571097-11 dbms:oracle
ALTER TABLE FALL ADD CONSTRAINT FALLPK PRIMARY KEY (ID) USING INDEX FALLPK;

-- changeset hermchr:1707764571097-12 dbms:oracle
ALTER TABLE FALL_GNR DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-13 dbms:oracle
CREATE INDEX FALL_GNRPK ON FALL_GNR(ID);

-- changeset hermchr:1707764571097-14 dbms:oracle
ALTER TABLE FALL_GNR ADD CONSTRAINT FALL_GNRPK PRIMARY KEY (ID) USING INDEX FALL_GNRPK;

-- changeset hermchr:1707764571097-15 dbms:oracle
ALTER TABLE GNR DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-16 dbms:oracle
CREATE INDEX GNRPK ON GNR(ID);

-- changeset hermchr:1707764571097-17 dbms:oracle
ALTER TABLE GNR ADD CONSTRAINT GNRPK PRIMARY KEY (ID) USING INDEX GNRPK;

-- changeset hermchr:1707764571097-18 dbms:oracle
ALTER TABLE ICD_CODE DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-19 dbms:oracle
CREATE INDEX ICD_CODEPK ON ICD_CODE(ID);

-- changeset hermchr:1707764571097-20 dbms:oracle
ALTER TABLE ICD_CODE ADD CONSTRAINT ICD_CODEPK PRIMARY KEY (ID) USING INDEX ICD_CODEPK;

The Entities look like this:

@Entity
@Table(
        name = "FALL",
        uniqueConstraints = {
                @UniqueConstraint(
                        name = "UC_FALL_KEY_QUARTAL",
                        columnNames = {"FALL_KEY", "QUARTAL"}
                )
        },
        indexes = {
                @Index(name = "FALLPK", columnList = "ID"),
                @Index(name = "IXUC_FALL_KEY_QUARTAL", columnList = "FALL_KEY, QUARTAL")
        }
)
public class FallEntity extends ImportEntityBase {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_FALL")
  @SequenceGenerator(name = "SEQ_FALL", allocationSize = 1)
  @Column(name = "ID", nullable = false, updatable = false)
  private Long id;
...

@MalloD12 MalloD12 reopened this Feb 19, 2024
@github-project-automation github-project-automation bot moved this from Done to Candidate in Liquibase Open Source Feb 19, 2024
@kevin-atx kevin-atx moved this from Candidate to In Development PR Issues in Liquibase Open Source Feb 27, 2024
@kevin-atx kevin-atx moved this from In Development PR Issues to Planned in Liquibase Open Source Feb 27, 2024
@filipelautert filipelautert moved this from Planned to Foundation Team Tickets in Liquibase Open Source Mar 7, 2024
@filipelautert filipelautert removed their assignment Mar 7, 2024
@vsprabhakaran
Copy link

The liquibase-hibernate is an excellent tool but this bug makes it cumbersome to use it effectively.

Hoping for quick resolution here.

I can confirm we still have such an issue with liquibase-hibernate 4.25.0

Basically it drops all PK and FK Constraints and creates them again.

Examples of generated Sql (we add the dbms:oracle) afterwards:

-- changeset hermchr:1707764571097-1 dbms:oracle
ALTER TABLE FALL_GNR DROP CONSTRAINT FK_FALL_ID;

-- changeset hermchr:1707764571097-3 dbms:oracle
ALTER TABLE FALL_GNR DROP CONSTRAINT FK_GNR_ID;

-- changeset hermchr:1707764571097-2 dbms:oracle
ALTER TABLE FALL_GNR ADD CONSTRAINT FK_FALL_ID FOREIGN KEY (FALL_ID) REFERENCES FALL (ID);

-- changeset hermchr:1707764571097-4 dbms:oracle
ALTER TABLE FALL_GNR ADD CONSTRAINT FK_GNR_ID FOREIGN KEY (GNR_ID) REFERENCES GNR (ID);

-- changeset hermchr:1707764571097-5 dbms:oracle
ALTER SEQUENCE SEQ_FALL INCREMENT BY 1;

-- changeset hermchr:1707764571097-6 dbms:oracle
ALTER SEQUENCE SEQ_FALL_GNR INCREMENT BY 1;

-- changeset hermchr:1707764571097-7 dbms:oracle
ALTER SEQUENCE SEQ_GNR INCREMENT BY 1;

-- changeset hermchr:1707764571097-8 dbms:oracle
ALTER SEQUENCE SEQ_ICD_CODE_GEN INCREMENT BY 1;

-- changeset hermchr:1707764571097-9 dbms:oracle
ALTER TABLE FALL DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-10 dbms:oracle
CREATE INDEX FALLPK ON FALL(ID);

-- changeset hermchr:1707764571097-11 dbms:oracle
ALTER TABLE FALL ADD CONSTRAINT FALLPK PRIMARY KEY (ID) USING INDEX FALLPK;

-- changeset hermchr:1707764571097-12 dbms:oracle
ALTER TABLE FALL_GNR DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-13 dbms:oracle
CREATE INDEX FALL_GNRPK ON FALL_GNR(ID);

-- changeset hermchr:1707764571097-14 dbms:oracle
ALTER TABLE FALL_GNR ADD CONSTRAINT FALL_GNRPK PRIMARY KEY (ID) USING INDEX FALL_GNRPK;

-- changeset hermchr:1707764571097-15 dbms:oracle
ALTER TABLE GNR DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-16 dbms:oracle
CREATE INDEX GNRPK ON GNR(ID);

-- changeset hermchr:1707764571097-17 dbms:oracle
ALTER TABLE GNR ADD CONSTRAINT GNRPK PRIMARY KEY (ID) USING INDEX GNRPK;

-- changeset hermchr:1707764571097-18 dbms:oracle
ALTER TABLE ICD_CODE DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1707764571097-19 dbms:oracle
CREATE INDEX ICD_CODEPK ON ICD_CODE(ID);

-- changeset hermchr:1707764571097-20 dbms:oracle
ALTER TABLE ICD_CODE ADD CONSTRAINT ICD_CODEPK PRIMARY KEY (ID) USING INDEX ICD_CODEPK;

The Entities look like this:

@Entity
@Table(
        name = "FALL",
        uniqueConstraints = {
                @UniqueConstraint(
                        name = "UC_FALL_KEY_QUARTAL",
                        columnNames = {"FALL_KEY", "QUARTAL"}
                )
        },
        indexes = {
                @Index(name = "FALLPK", columnList = "ID"),
                @Index(name = "IXUC_FALL_KEY_QUARTAL", columnList = "FALL_KEY, QUARTAL")
        }
)
public class FallEntity extends ImportEntityBase {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_FALL")
  @SequenceGenerator(name = "SEQ_FALL", allocationSize = 1)
  @Column(name = "ID", nullable = false, updatable = false)
  private Long id;
...

@fuitattila
Copy link

We are still encountering an issue with liquibase-hibernate (using maven diff generation) version 4.27.0.

The generated xml look like that:

<?xml version="1.0" encoding="UTF-8"?><databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="attila (generated)" id="1712755908477-1">
<dropUniqueConstraint constraintName="UC_EMAILSUBSCRIPTION_KEY_COL" tableName="email"/>
</changeSet>
<changeSet author="attila (generated)" id="1712755908477-2">
<addUniqueConstraint columnNames="subscription_key" constraintName="UC_EMAILSUBSCRIPTION_KEY_COL" tableName="email"/>
</changeSet>
</databaseChangeLog>

@tati-qalified
Copy link

Hi @vsprabhakaran and @fuitattila, thank you for letting us know. We'll look into this again and get back to you.

@filipelautert filipelautert self-assigned this Apr 10, 2024
@filipelautert filipelautert moved this from Foundation Team Tickets to Development in Liquibase Open Source Apr 10, 2024
@filipelautert
Copy link
Collaborator

Hello @tati-qalified @jonenst - are you able to help testing the fix on PR #679 ( https://github.com/liquibase/liquibase-hibernate/actions/runs/8656431018/artifacts/1407347218) ?

@filipelautert filipelautert moved this from Development to In Development PR Issues in Liquibase Open Source Apr 12, 2024
@Guschtel
Copy link
Contributor

Guschtel commented Apr 19, 2024

@filipelautert that did not fix it for me or I did something wrong:

In my build.gradle I loaded the jar and hibernate-core as a replacement to the normal dependency (liquibaseRuntime "org.liquibase.ext:liquibase-hibernate6:${liquibaseVersion}")

    liquibaseRuntime "org.hibernate.orm:hibernate-core:6.4.4.Final"
    liquibaseRuntime files("../../libs/liquibase-hibernate6-4.27.0-SNAPSHOT.jar")

It did improve the situation.

But the primary keys were still dropped:

image

@filipelautert
Copy link
Collaborator

Thanks for the testing @Guschtel ! I pushed more fixes for PK and Sequences, could you try again?

@Tristan-WorkGH
Copy link

@filipelautert
I tested the artifact 1407347218, and it resolved the problem for uniques constraints for us.

@github-project-automation github-project-automation bot moved this from In Development PR Issues to Done in Liquibase Open Source Apr 24, 2024
@Guschtel
Copy link
Contributor

@filipelautert it fixes a few cases, but not all of them.

I still have issues with sequences that all get an alter table statement:

-- changeset hermchr:1714384768211-1 dbms:oracle
ALTER SEQUENCE SEQ_FALL INCREMENT BY 1;

-- changeset hermchr:1714384768211-2 dbms:oracle
ALTER SEQUENCE SEQ_FALL_GNR INCREMENT BY 1;

-- changeset hermchr:1714384768211-3 dbms:oracle
ALTER SEQUENCE SEQ_GNR INCREMENT BY 1;

-- changeset hermchr:1714384768211-4 dbms:oracle
ALTER SEQUENCE SEQ_ICD_CODE_GEN INCREMENT BY 1;

-- changeset hermchr:1714384768211-5 dbms:oracle
ALTER SEQUENCE SEQ_KK INCREMENT BY 1;

It also drops the primary Keys:

-- changeset hermchr:1714384768211-10 dbms:oracle
ALTER TABLE FALL DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1714384768211-11 dbms:oracle
CREATE INDEX FALLPK ON FALL(ID);

-- changeset hermchr:1714384768211-12 dbms:oracle
ALTER TABLE FALL ADD CONSTRAINT FALLPK PRIMARY KEY (ID) USING INDEX FALLPK;

-- changeset hermchr:1714384768211-13 dbms:oracle
ALTER TABLE FALL_GNR DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1714384768211-14 dbms:oracle
CREATE INDEX FALL_GNRPK ON FALL_GNR(ID);

-- changeset hermchr:1714384768211-15 dbms:oracle
ALTER TABLE FALL_GNR ADD CONSTRAINT FALL_GNRPK PRIMARY KEY (ID) USING INDEX FALL_GNRPK;

They are defined like this:

Entity
@Table(
  name = "FALL",
  uniqueConstraints = {
    @UniqueConstraint(name = "UC_FALL_KEY_QUARTAL", columnNames = { "FALL_KEY", "QUARTAL" }),
  },
  indexes = {
    @Index(name = "FALLPK", columnList = "ID"),
    @Index(name = "IXUC_FALL_KEY_QUARTAL", columnList = "FALL_KEY, QUARTAL"),
  }
)
public class FallEntity extends ImportEntityBase {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_FALL_GEN")
  @SequenceGenerator(name = "SEQ_FALL_GEN", allocationSize = 1, sequenceName = "SEQ_FALL")
  @Column(name = "ID", nullable = false, updatable = false)
  private Long id;

...

The resulting SQL was:

-- changeset hermchr:1707828645796-5 dbms:oracle
CREATE TABLE FALL
(
    ID                 NUMBER(19, 0) GENERATED BY DEFAULT AS IDENTITY NOT NULL,
...
    CONSTRAINT FALLPK PRIMARY KEY (ID)
);

The sequence was initially created by this sql:

CREATE SEQUENCE SEQ_FALL START WITH 1 INCREMENT BY 1;

@Guschtel
Copy link
Contributor

I just tested the latest nightly build https://github.com/liquibase/liquibase-hibernate/actions/runs/8874569931

With that it looks better, the problems with the sequences are gone 👍

Remaining are only the problems with the primary key:

-- changeset hermchr:1714391751631-8 dbms:oracle
ALTER TABLE FALL DROP PRIMARY KEY DROP INDEX;

-- changeset hermchr:1714391751631-9 dbms:oracle
CREATE INDEX FALLPK ON FALL(ID);

-- changeset hermchr:1714391751631-10 dbms:oracle
ALTER TABLE FALL ADD CONSTRAINT FALLPK PRIMARY KEY (ID) USING INDEX FALLPK;

@filipelautert
Copy link
Collaborator

@Guschtel almost there!
Are you using the mappings from comment #436 (comment) ? And what database are you using, Oracle?

@Guschtel
Copy link
Contributor

Guschtel commented Apr 29, 2024

@filipelautert I wrote down the latest mappings in #436 (comment), yes.

But they should be the same as before, i just added the sequence name with sequenceName = "SEQ_FALL" to match the name in the database (compared to my try in #436 (comment)).

Our database is Oracle Database 19c Enterprise Edition Release 19.0.0.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment