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

Proposed fix for #5442 - command "unexpectedChangesets" always reports at least 1 unexpected changeset with initial tag in database #5446

Merged
merged 6 commits into from Feb 29, 2024

Conversation

Tylorjg
Copy link
Contributor

@Tylorjg Tylorjg commented Jan 8, 2024

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Issue #5442 outlines an odd behavior where the unexpected-changesets command shows the tag changeset as unexpected. If using the tag command itself, a changeset is not added to the changelog, but an internal Liquibase changeset will be added to the DBCL table. This would cause the unexpected-changesets to always show the internal Liquibase changeset as unexpected. Side note, the generate-changelog does not create the changeset in a changelog if it exists in the DBCL, so there isn't a way to make the tag expected.

This fix adds a function that is called first to determine if the file path is the liquibase-internal changeset. If it is, it removes it from the unexpected list.

Fixes #5442

Things to be aware of

I couldn't find a way to capture the file path for the ran changeset in the RanChangesSet.java file, so I did the same call that occurs in the isSameAs function (occurs in the isSamePath function technically), so it could be refactored to be more efficient.

Things to worry about

There isn't any additional tests associated with the change. I have found that there is a file unexpectedChangesets.test.groovy, but was unsure how to get the tag command to execute first. I would be happy to write test cases/modify the existing ones.

Additional Context

N/A

@kevin-atx kevin-atx changed the title Proposed fix for #5442 Proposed fix for #5442 - command "unexpectedChangesets" always reports at least 1 unexpected changeset with initial tag in database Jan 16, 2024
@MalloD12 MalloD12 self-requested a review January 18, 2024 15:34
@MalloD12 MalloD12 self-assigned this Jan 18, 2024
Copy link
Contributor

@MalloD12 MalloD12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Tylorjg,

Thank you for adding submitting this PR to fix #5442. I was thinking maybe we can only update isSameAs() by also checking whether filepath is equals to "liquibase-internal" . Something like this:

public boolean isSameAs(ChangeSet changeSet) {
        return isSamePath("liquibase-internal") || (
                this.getId().equalsIgnoreCase(changeSet.getId())
                && this.getAuthor().equalsIgnoreCase(changeSet.getAuthor())
                && isSamePath(changeSet.getFilePath()));
    }

Then we don't need to create a new method nor update ExpectedChangesVisitor class.

Regarding tests, I think it would be nice if we can add some integration test here by creating a new class (UnexpectedChangesetsCommandStepTest), for adding this test you can also use CommandUtil test class where you have a runTag() and probably you can also add a runUnexpectedChangeset() to validate the given issue.

Please let me know if you have any question/concerns.

Thanks,
Daniel.

Copy link
Contributor

@MalloD12 MalloD12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Thanks @Tylorjg for submitting this PR and addressing my review comment. I have manually tested this change, plus also adding a basic integration test to validate your fix against MySQL in this case, but it could against any DB.

Build and test checks have been successfully executed (there are some functional test failing, but that doesn't seem to be related with this change.

Copy link
Contributor

@rberezen rberezen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tylorjg @filipelautert @MalloD12
The fix introduces a regression. So, if you execute the following commands:

  1. liquibase tag tag1
  2. liquibase update
  3. liquibase history

you will observe that it appears as though nothing was deployed; the databasechangelog will be empty, but the deployed objects will exist in the database.
image
image

@MalloD12
Copy link
Contributor

@Tylorjg would you mind looking at the regression issue @rberezen mentioned above?

Thanks,
Daniel.

@MalloD12
Copy link
Contributor

Code changes look good to me, thank you for taking care of this regression issue @Tylorjg.

@rberezen would you mind trying again when you have a chance?

Thanks,
Daniel.

@Tylorjg Tylorjg requested a deployment to external February 19, 2024 19:21 — with GitHub Actions Abandoned
@rberezen
Copy link
Contributor

Thank you, @Tylorjg, for your contribution!
@MalloD12, I've manually tested and verified the test results - everything looks good!

…nction, isSameAsIgnoreLiquibaseInternalChangeset to ignore the liquibase-internal filepath.
Tylorjg and others added 4 commits February 27, 2024 14:57
- Add runUnexpectedChangeSet method to CommandUtil class.
- Add unexpected changeset test to validate running a tag to the database is not reported as a unexpected changeset.
…so I expanded the removeIf predicate to be two conditions. This solves the issue of changesets not showing up in the DBCL table.
@filipelautert filipelautert merged commit 4da8d95 into liquibase:master Feb 29, 2024
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

command "unexpectedChangesets" always reports at least 1 unexpected changeset with initial tag in database
4 participants