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

Fix DatabaseFactory db loading when Database implementation is specified (fix for Issues 5371 & 5396 ) #5397

Merged
merged 10 commits into from
Jan 15, 2024

Conversation

dhsmith1001
Copy link
Contributor

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

When a specific Database implementation is specified (e.g. with --databaseClass using CLI), the DatabaseFactory loads only that Database instance in its implementedDatabases HashMap. This causes a failure when code such as DatabaseList.validateDefinitions() (line 88) tries to verify the database shortnames in the dbms attribute of a changeSet or createProcedure element.

This PR changes the behavior of DatabaseFactory so that it loads all Database instances when a databaseClass is provided, but also keeps track of the class specified. It will provide the specified database for the relevant shortName, but will also still return the appropriate Database instance for shortNames other than that of the specified database.

Things to be aware of

  • A new private member variable was added to DatabaseFactory: specifiedDbClass
  • The getDatabase() method was changed to return the specifiedDbClass instance when its shortName is passed as the parameter

Things to worry about

Additional Context

Copy link
Collaborator

@filipelautert filipelautert left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @dhsmith1001 ! I'm moving it ahead for test review.

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.

@dhsmith1001 code changes look good to me, although I was going to propose creating a separate method as I thought the updated method was used by an integration, but looking into the details of the reported issue it was reproduced using CLI so let's leave it like that for now and I'll discuss it with the team next week.

I would like to see some integration tests here in this PR. I thought it would be a good idea to use one of the changelogs (TestChangelogOld.xml) you provided and run an update command setting the databaseClass property and one without setting that up. Could you do that for us? If you need any help I'll be here starting Tuesday to guide you.

Thanks,
Daniel.

@dhsmith1001
Copy link
Contributor Author

dhsmith1001 commented Jan 3, 2024

@dhsmith1001 code changes look good to me, although I was going to propose creating a separate method as I thought the updated method was used by an integration, but looking into the details of the reported issue it was reproduced using CLI so let's leave it like that for now and I'll discuss it with the team next week.

I would like to see some integration tests here in this PR. I thought it would be a good idea to use one of the changelogs (TestChangelogOld.xml) you provided and run an update command setting the databaseClass property and one without setting that up. Could you do that for us? If you need any help I'll be here starting Tuesday to guide you.

Thanks, Daniel.

@MalloD12 I'm happy to add an integration test. What kind of test you have in mind? I see several possibilities in liquibase-integration-tests, e.g. a new method in LiquibaseCommandLineTest or a new test class under src/test/groovy/liquibase/command/core/. Is there a specific test that would make a good example?

@MalloD12
Copy link
Contributor

MalloD12 commented Jan 3, 2024

@dhsmith1001 code changes look good to me, although I was going to propose creating a separate method as I thought the updated method was used by an integration, but looking into the details of the reported issue it was reproduced using CLI so let's leave it like that for now and I'll discuss it with the team next week.
I would like to see some integration tests here in this PR. I thought it would be a good idea to use one of the changelogs (TestChangelogOld.xml) you provided and run an update command setting the databaseClass property and one without setting that up. Could you do that for us? If you need any help I'll be here starting Tuesday to guide you.
Thanks, Daniel.

@MalloD12 I'm happy to add an integration test. What kind of test you have in mind? I see several possibilities in liquibase-integration-tests, e.g. a new method in LiquibaseCommandLineTest or a new test class under src/test/groovy/liquibase/command/core/. Is there a specific test that would make a good example?

Hi @dhsmith1001,

Yeap, I think LiquibaseCommandLineTest test suite would be a good place. What we can do is if you want you can create the same test class under the Groovy directory and then we can migrate the other test in the Java class, I can do that if you prefer.

Thanks,
Daniel.

@dhsmith1001
Copy link
Contributor Author

@MalloD12 I added a test to LiquibaseCommandLineTest.java. I opted not to convert it to Groovy as that's not my strength. Hope this is OK.

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 @dhsmith1001 for this PR and for taking the time to add a test to it. I have added another based on the one you added, but without specifying a databaseClass. Also, I had to change the database used in these tests, because HSQL driver used was not compatible with Java8, so I decided to use H2 instead. Other than that code changes looks good, build and test checks are successfully executed.

Thanks,
Daniel.

@filipelautert filipelautert added this to the 1NEXT milestone Jan 15, 2024
@filipelautert filipelautert merged commit 948f4f7 into liquibase:master Jan 15, 2024
29 of 31 checks passed
@filipelautert filipelautert changed the title Proposed fix for Issues 5371 & 5396 Fix DatabaseFactory db loading when Database implementation is specified (fix for Issues 5371 & 5396 ) Jan 15, 2024
@dhsmith1001
Copy link
Contributor Author

Thanks @MalloD12! Any estimate on when 4.25.2 will be released?

@MalloD12
Copy link
Contributor

Thanks @MalloD12! Any estimate on when 4.25.2 will be released?

We are aiming to have our next release around the end of January or the beginning of February.

Thanks,
Daniel.

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.

None yet

5 participants