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

Wrong dependency order when generating diffChangeLog for addColumn --> addPrimaryKey #1722

Closed
szandany opened this issue Feb 25, 2021 · 11 comments
Assignees

Comments

@szandany
Copy link
Contributor

szandany commented Feb 25, 2021

Environment

Liquibase Version:
4.3.1
Liquibase Integration & Version:
CLI
Database Vendor & Version:
PostgreSQL
Operating System Type & Version:
Linux, Windows
changeLog format:
XML, YAML, JSON, Formatted SQL

Description

When generating a diffChangLog between the target schema and the reference schema, the resulting changeLog will reflect changes in the wrong order for addColumn --> addPrimaryKey change sets order.
This issue is happening for all changeLog formats.

Steps To Reproduce

  1. Run the following changeSet in the reference schema to create a table "person" --> add column --> add PK
<changeSet  author="SteveZ"  id="createTable-person">
    <createTable tableName="person">  
        <column  name="address"  type="varchar(255)"/>  
    </createTable>  
</changeSet>
<changeSet id="SteveZ" author="234fre">
    <addColumn tableName="person">
        <column name="id" type="varchar(255)"/>
    </addColumn>
</changeSet>
<changeSet id="SteveZ" author="rtg45">
    <addPrimaryKey tableName="person" columnNames="id" constraintName="pk_person"/>
</changeSet>
  1. Run the following changeSet in the target schema to create a table "person"
<changeSet  author="SteveZ"  id="createTable-person">
    <createTable tableName="person">  
        <column  name="address"  type="varchar(255)"/>  
    </createTable>  
</changeSet>
  1. Run liquibase diffChangeLog between the reference schema and the target schema.

Actual Behavior

The resulting changeSets in the generated changeLog will look like the following:

<changeSet author="support.liquibase.net (generated)" id="1614270028483-1">
    <addPrimaryKey columnNames="id" constraintName="pk_person" tableName="person"/>
</changeSet>
<changeSet author="support.liquibase.net (generated)" id="1614270028483-2">
    <addColumn tableName="person">
        <column name="id" type="varchar(255 BYTE)">
            <constraints nullable="false"/>
        </column>
    </addColumn>
</changeSet>

The primary key creation and add column creation are in the wrong order.

Expected/Desired Behavior

<changeSet author="support.liquibase.net (generated)" id="1614270028483-2">
    <addColumn tableName="person">
        <column name="id" type="varchar(255 BYTE)">
            <constraints nullable="false"/>
        </column>
    </addColumn>
</changeSet>
<changeSet author="support.liquibase.net (generated)" id="1614270028483-1">
    <addPrimaryKey columnNames="id" constraintName="pk_person" tableName="person"/>
</changeSet>
@wwillard7800
Copy link
Contributor

@szandany Did you test this against any previous versions of Liquibase?

@szandany
Copy link
Contributor Author

@wwillard7800 Yes. This was tested with 4.0.0 as well.

@wwillard7800
Copy link
Contributor

Did it work in that version?

@szandany
Copy link
Contributor Author

No. I got the same result.

@XDelphiGrl
Copy link
Contributor

I'm going to give this a try now, @szandany. This is a very basic use case that should be working (of course!). Thanks for bringing our attention to the issue.

@XDelphiGrl
Copy link
Contributor

I can reproduce the bug following your steps, @szandany. I'd raise this to Product to make sure it gets added to a sprint. Thanks for the excellent bug report!

@nvoxland
Copy link
Contributor

nvoxland commented Mar 16, 2021

Fixed in #1733

@nvoxland
Copy link
Contributor

nvoxland commented Apr 5, 2021

Fix #1733 merged into master for 4.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants