question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

preConditions onSqlOutput TEST configuration does not work for nested changelogs

See original GitHub issue

Liquibase Version: 3.6.3 (but same code on master)

Liquibase Integration & Version: <Pick one: CLI, maven, gradle, spring boot, servlet, etc.> maven

Description

onSqlOutput does not work, if it is used in a nested changelog.

Steps To Reproduce

  • Create a config with changelog A importing changelog B.
  • Add a changeset in B with a PreCondition which will always fail.
  • Use the update-sql command

Actual Behavior

No error, and any SQL in B will be printed, although the condition failed

Expected/Desired Behavior

The command stopping/not outputing the SQL in B.

Workaround

Add an empty preCondition config to all “parent” changelogs, with the setting onSqlOutput: TEST

Cause

liquibase.precondition.core.PreconditionContainer#check processes preConditions in a top-down way. Nested Containers will only be evaluated, if the parent’s testPrecondtion is true:

if (testPrecondition) {
    super.check(database, changeLog, changeSet, changeExecListener);
}

As soon as one does not or is missing (and defaults to IGNORE), all nested preconditions will not be tested and all SQL will be printed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nvoxlandcommented, Aug 4, 2021

I added a PR to fix the issue.

Your new example helped a lot, thanks

0reactions
NSC-nwestcommented, Nov 18, 2021

Hello, I ran into this issue as well. Will this allow me to generate SQL with updateSQL that ignores the failures?

parent changelog.yaml:

  • include: file: child-changelog.yaml relativeToChangelogFile: true

child-changelog,yaml: databaseChangeLog:

  • preConditions:
    • onSqlOutput: TEST
    • onFail: CONTINUE
    • onFailMessage: “Mocks will not be created.”
    • changeLogPropertyDefined: property: create-mocks

My goal here is to generate the SQL only if the create-mocks property is defined, when using the updateSql command. Currently this seems to blow up no matter what I do in the parent changelog (adding onSqlOutput: TEST & onFail: CONTINUE, etc).

The reason I am doing this is for our sandboxes where rebuilding the entire database every time for developers is time consuming so we generate the SQL, clean it up, and then run it as a big blob.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preconditions | Liquibase Docs
Control what changesets are run and not run based on the state of the database. You can use all Liquibase preconditions in XML,...
Read more >
2 preconditions in one liquibase changeset - Stack Overflow
It's not possible to create column inside condition. If I understand your problem, then you have two (maybe more) options:.
Read more >
Precondition evaluation in nested changelog files
Hi everybody, I have the following situation. My master change log file contains two include entries (changelog files).
Read more >
How to use Liquibase for the versioning of the database schema
In this article, I'll explain how Liquibase can be used in a Java project, with Spring/Hibernate, to version the database schema.
Read more >
Howto set/override changeset description - Liquibase Forums
Next Re : Upgrading from 2.0.5 to 3.2.0 - Problem with preConditions ? Previous Re : Track Database changes made with out using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found