`foreignKeyConstraintExists` not working
See original GitHub issueEnvironment
Liquibase Version:
./bin/liquibase --version
####################################################
## _ _ _ _ ##
## | | (_) (_) | ##
## | | _ __ _ _ _ _| |__ __ _ ___ ___ ##
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ ##
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ ##
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| ##
## | | ##
## |_| ##
## ##
## Get documentation at docs.liquibase.com ##
## Get certified courses at learn.liquibase.com ##
## Free schema change activity reports at ##
## https://hub.liquibase.com ##
## ##
####################################################
Starting Liquibase at 17:02:20 (version 4.7.0 #1140 built at 2022-01-07 19:26+0000)
Liquibase Version: 4.7.0
Liquibase Community 4.7.0 by Liquibase
Running Java under /usr/java/jdk1.8.0_144/jre (Version 1.8.0_144)
Note: The same Liquibase changeSet worked in Liquibase Version: 3.10.2
Liquibase Integration & Version: CLI
Liquibase Extension(s) & Version:
Database Vendor & Version:
> SELECT version();
version
------------------------------------------------------------------------------
PostgreSQL 10.13 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.9.3, 64-bit
Operating System Type & Version:
$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
Description
foreignKeyConstraintExists
doesn’t seem to be working.
I’m trying to MARK_RAN
if foreignKey already exists so I just create the FK if it is absent.
This was working with Liquibase 3.10.2. I’m in the process of upgrading it in order to improve performance as a simple migration took multiple hours with the previous version.
Steps To Reproduce
<changeSet ...>
<preConditions onFail="MARK_RAN">
<not>
<foreignKeyConstraintExists foreignKeyName="FK_NAME"/>
</not>
</preConditions>
<addForeignKeyConstraint constraintName="FK_NAME" ... />
</changeSet>
Actual Behavior
changeSet execution fails trying to execute the addForeignKeyConstraint
(since the constraint with that name already exists).
Expected/Desired Behavior
The precondition onFail should’ve been called (adding the changeSet as MARK_RAN
to liquibase changelog), and, as such, the changeSet shouldn’t execute addForeignKeyContstraint
.
Additional Context
I was able to implement a temporary workaround specific to the database vendor that confirms that the FK exists.
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
SELECT COUNT(*) FROM information_schema.table_constraints WHERE constraint_name='FK_NAME' AND table_schema = '<x>'
</sqlCheck>
</preConditions>
From my (limited) understanding, Liquibase does some sort of DB snapshot, which it uses to verify some of these pre-conditions (not the sqlCheck
) and it doesn’t seem to be importing the ForeignKey to that snapshot.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top GitHub Comments
@joserebelo
Awesome, thanks.
@kataggart Thanks for taking another look.
@liam-verta sorry for delay here; will raise it with the team again and see what we might be able to do. Thanks @joserebelo for the PR.