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

ColumnExistsPrecondition throws error when table is missing #5271

Closed
2 tasks done
Januson opened this issue Nov 22, 2023 · 3 comments · Fixed by #5282
Closed
2 tasks done

ColumnExistsPrecondition throws error when table is missing #5271

Januson opened this issue Nov 22, 2023 · 3 comments · Fixed by #5282

Comments

@Januson
Copy link
Contributor

Januson commented Nov 22, 2023

Search first

  • I searched and no similar issues were found

Description

In Liquibase version 4.24.0 precondition columnExists evaluated as false when the target table was missing. In version 4.25.0 the precondition throws PreconditionErrorException. Documentation of columnExists doesn't specify this behavior and 4.25.0 release notes do not mention any changes to it so I suppose it wasn't intentional.

Steps To Reproduce

Run any changeset with a precondition columnExists targeting a table that does not exist.

Reproducer: https://github.com/Januson/liquibase-error

Expected/Desired Behavior

Precondition should not fail and instead should evaluate as false.

Liquibase Version

4.25.0

Database Vendor & Version

HSQLDB

Liquibase Integration

No response

Liquibase Extensions

No response

OS and/or Infrastructure Type/Provider

No response

Additional Context

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR (Thank you!)
@MalloD12
Copy link
Contributor

Thanks, @Januson for raising this issue. We have planned to review #5246 soon which I think could be related. Would you be keen on submitting a PR to fix it? We can provide any guidance/details you need.

Thanks,
Daniel.

@Januson
Copy link
Contributor Author

Januson commented Nov 24, 2023

@MalloD12 Sure, I can submit a PR.

Januson pushed a commit to Januson/liquibase that referenced this issue Nov 24, 2023
Januson pushed a commit to Januson/liquibase that referenced this issue Nov 24, 2023
Januson pushed a commit to Januson/liquibase that referenced this issue Nov 24, 2023
…is missing

- Handled DatabaseException thrown by PreparedStatement when the table
  is missing
- Added integration test

Fixes liquibase#5271
@tati-qalified
Copy link
Contributor

Hi @Januson and @MalloD12, I looked into this issue (as well as #5246 ) and I found that it's database-specific, and only the columnExists precondition is failing. Similar preconditions such as tableExists work with no issues.

This is reproducible using H2 and HyperSQL databases

It is not reproducible using:

  • PostgreSQL
  • MySQL
  • MSSQL
  • Oracle
  • DB2

Analysing the error logs, here's the output for PostgreSQL:

Unexpected error running Liquibase: Migration failed for changeset changelog.xml::2::testing:
     Reason:
          changelog.xml : Column public.thisDoesNotExist.column1 does not exist
  - Caused by: Preconditions Failed

Note that it says "Preconditions Failed".
This is the same output as for MySQL, MSSQL, etc.

Now, for H2:

Unexpected error running Liquibase: Migration failed for changeset changelog.xml::2::testing:
     Reason:
          changelog.xml : liquibase.precondition.core.ColumnExistsPrecondition@6b3f6585 : Table "THISDOESNOTEXIST" not found; SQL statement:
select t.column1 from PUBLIC.thisDoesNotExist t where 0=1 [42102-224]
  - Caused by: Precondition Error
  - Caused by: Table "THISDOESNOTEXIST" not found; SQL statement:
select t.column1 from PUBLIC.thisDoesNotExist t where 0=1 [42102-224]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
        at org.h2.message.DbException.get(DbException.java:223)
        at org.h2.message.DbException.get(DbException.java:199)
....

In this case, it says "Precondition Error".

And for HyperSQL:

Unexpected error running Liquibase: Migration failed for changeset changelog.xml::2::testinga:
     Reason:
          changelog.xml : liquibase.precondition.core.ColumnExistsPrecondition@3dd818e8 : user lacks privilege or object not found: THISDOESNOTEXIST in statement [select t.column1 from PUBLIC.thisDoesNotExist t where 0=1]
  - Caused by: Precondition Error

Also outputs "Precondition Error".

MalloD12 pushed a commit that referenced this issue Nov 28, 2023
- Handled DatabaseException thrown by PreparedStatement when the table
  is missing
- Added integration test

Fixes #5271
filipelautert pushed a commit to Januson/liquibase that referenced this issue Dec 4, 2023
…is missing

- Handled DatabaseException thrown by PreparedStatement when the table
  is missing
- Added integration test

Fixes liquibase#5271
filipelautert pushed a commit that referenced this issue Dec 4, 2023
#5282)

* Fix #5271: ColumnExistsPrecondition throws error when table is missing

- Handled DatabaseException thrown by PreparedStatement when the table
  is missing
- Added integration test

Fixes #5271

* Column exists precondition checkfast clean up.

* - Moved result set assignment inside try, in order to trigger its close method automatically.
- Extract nested tries in separate methods to resolve existent code smells reported by sonar.

---------

Co-authored-by: Daniel Mallorga <dmallorga@liquibase.com>
mick-stewart73 added a commit to ikasanEIP/ikasan that referenced this issue Dec 17, 2023
mick-stewart73 added a commit to ikasanEIP/ikasan that referenced this issue Jan 12, 2024
mick-stewart73 added a commit to ikasanEIP/ikasan that referenced this issue Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
3 participants